r85044 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85043‎ | r85044 | r85045 >
Date:20:31, 30 March 2011
Author:krinkle
Status:deferred
Tags:
Comment:
Adding test version of subclass for TWN extension:translate
Modified paths:
  • /trunk/tools/ToolserverI18N/ToolserverTextdomains.php (added) (history)
  • /trunk/tools/ToolserverI18N/toolserver-defines.txt (deleted) (history)
  • /trunk/tools/ToolserverI18N/toolserver-textdomains.txt (added) (history)

Diff [purge]

Index: trunk/tools/ToolserverI18N/toolserver-defines.txt
@@ -1,10 +0,0 @@
2 -General
3 -
4 -Getwikiapi
5 -ignored = title
6 -
7 -Svgtranslate
8 -optional = format-filename-example, format-fullurl-example
9 -
10 -Tsintuition
11 -ignored = title
\ No newline at end of file
Index: trunk/tools/ToolserverI18N/ToolserverTextdomains.php
@@ -0,0 +1,152 @@
 2+<?php
 3+/**
 4+ * Classes for %Toolserver tools translation for TranslateWiki.net
 5+ *
 6+ * @file
 7+ * @author Niklas Laxström
 8+ * @author Krinkle
 9+ * @copyright Copyright © 2008-2010, Niklas Laxström
 10+ * @copyright Copyright © 2011, Krinkle
 11+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 12+ */
 13+
 14+/**
 15+ * Support for tools using TsIntuition at the Toolserver.
 16+ */
 17+class PremadeToolserverTextdomains extends PremadeMediawikiExtensionGroups {
 18+ protected $useConfigure = false;
 19+ protected $groups;
 20+ protected $idPrefix = 'tsi18n-';
 21+ protected $namespaces = array( NS_TOOLSERVER, NS_TOOLSERVER_TALK );
 22+
 23+
 24+ public function __construct() {
 25+ global $wgTranslateGroupRoot;
 26+
 27+ parent::__construct();
 28+ $dir = dirname( __FILE__ );
 29+ $this->definitionFile = $dir . '/toolserver-textdomains.txt';
 30+ $this->path = "$wgTranslateGroupRoot/ToolserverI18N/language/messages/";
 31+ }
 32+
 33+ /// Initialisation function
 34+ public function init() {
 35+ if ( $this->groups !== null ) return;
 36+
 37+ $defines = file_get_contents( $this->definitionFile );
 38+
 39+ $linefeed = '(\r\n|\n)';
 40+
 41+ $sections = array_map( 'trim', preg_split( "/$linefeed{2,}/", $defines, - 1, PREG_SPLIT_NO_EMPTY ) );
 42+
 43+ $groups = $fixedGroups = array();
 44+
 45+ foreach ( $sections as $section ) {
 46+ $lines = array_map( 'trim', preg_split( "/$linefeed/", $section ) );
 47+ $newgroup = array();
 48+
 49+ foreach ( $lines as $line ) {
 50+ if ( $line === '' || $line[0] === '#' ) continue;
 51+
 52+ if ( strpos( $line, '=' ) === false ) {
 53+ if ( empty( $newgroup['name'] ) ) {
 54+ $newgroup['name'] = $line;
 55+ } else {
 56+ throw new MWException( "Trying to define name twice: " . $line );
 57+ }
 58+ } else {
 59+ list( $key, $value ) = array_map( 'trim', explode( '=', $line, 2 ) );
 60+ switch ( $key ) {
 61+ case 'file':
 62+ case 'var':
 63+ case 'id':
 64+ case 'descmsg':
 65+ $newgroup[$key] = $value;
 66+ break;
 67+ case 'optional':
 68+ case 'ignored':
 69+ $values = array_map( 'trim', explode( ',', $value ) );
 70+ if ( !isset( $newgroup[$key] ) ) {
 71+ $newgroup[$key] = array();
 72+ }
 73+ $newgroup[$key] = array_merge( $newgroup[$key], $values );
 74+ break;
 75+ case 'prefix':
 76+ $prefix = trim( $value );
 77+ if ( isset( $newgroup['prefix'] ) && $newgroup['prefix'] !== $prefix ) {
 78+ throw new MWException( "Only one prefix supported: {$newgroup['prefix']} !== $prefix" );
 79+ }
 80+ $newgroup['prefix'] = $prefix;
 81+
 82+ break;
 83+ default:
 84+ throw new MWException( "Unknown key:" . $key );
 85+ }
 86+ }
 87+ }
 88+
 89+ if ( count( $newgroup ) ) {
 90+ if ( empty( $newgroup['name'] ) ) {
 91+ throw new MWException( "Name missing\n" . print_r( $newgroup, true ) );
 92+ }
 93+ $groups[] = $newgroup;
 94+ }
 95+ }
 96+
 97+
 98+ foreach ( $groups as $g ) {
 99+ if ( !is_array( $g ) ) {
 100+ $g = array( $g );
 101+ }
 102+
 103+ $name = $g['name'];
 104+
 105+ if ( isset( $g['id'] ) ) {
 106+ $id = $g['id'];
 107+ } else {
 108+ $id = $this->idPrefix . preg_replace( '/\s+/', '', strtolower( $name ) );
 109+ }
 110+
 111+ if ( isset( $g['file'] ) ) {
 112+ $file = $g['file'];
 113+ } else {
 114+ // TsIntuition text-domains are case-insensitive and internally
 115+ // converts to lowercase names starting with a capital letter.
 116+ // eg. "My Tool" -> "Mytool.i18n.php"
 117+ $sanatized = preg_replace( '/\s+/', '', ucfirst( strtolower( $name ) ) );
 118+ // No subdirectories
 119+ $file = "$sanatized.i18n.php";
 120+ }
 121+
 122+ if ( isset( $g['descmsg'] ) ) {
 123+ $descmsg = $g['descmsg'];
 124+ } else {
 125+ $descmsg = str_replace( $this->idPrefix, '', $id ) . '-desc';
 126+ }
 127+
 128+ if ( isset( $g['url'] ) ) {
 129+ $url = $g['url'];
 130+ } else {
 131+ $url = false;
 132+ }
 133+
 134+ $newgroup = array(
 135+ 'name' => $name,
 136+ 'file' => $file,
 137+ 'descmsg' => $descmsg,
 138+ 'url' => $url,
 139+ );
 140+
 141+ $copyvars = array( 'ignored', 'optional', 'var', 'prefix' );
 142+ foreach ( $copyvars as $var ) {
 143+ if ( isset( $g[$var] ) ) {
 144+ $newgroup[$var] = $g[$var];
 145+ }
 146+ }
 147+
 148+ $fixedGroups[$id] = $newgroup;
 149+ }
 150+
 151+ $this->groups = $fixedGroups;
 152+ }
 153+}
Property changes on: trunk/tools/ToolserverI18N/ToolserverTextdomains.php
___________________________________________________________________
Added: svn:eol-style
1154 + native
Index: trunk/tools/ToolserverI18N/toolserver-textdomains.txt
@@ -0,0 +1,10 @@
 2+General
 3+
 4+Getwikiapi
 5+ignored = title
 6+
 7+Svgtranslate
 8+optional = format-filename-example, format-fullurl-example
 9+
 10+Tsintuition
 11+ignored = title
\ No newline at end of file
Property changes on: trunk/tools/ToolserverI18N/toolserver-textdomains.txt
___________________________________________________________________
Added: svn:eol-style
112 + native

Status & tagging log