Index: trunk/extensions/Translate/scripts/tm-export.php |
— | — | @@ -4,7 +4,7 @@ |
5 | 5 | * |
6 | 6 | * @author Niklas Laxstrom |
7 | 7 | * |
8 | | - * @copyright Copyright © 2010, Niklas Laxström |
| 8 | + * @copyright Copyright © 2010-2011, Niklas Laxström |
9 | 9 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
10 | 10 | * @file |
11 | 11 | */ |
— | — | @@ -48,7 +48,8 @@ |
49 | 49 | $capitalized = MWNamespace::isCapitalized( $group->getNamespace() ); |
50 | 50 | $ns_text = $wgContLang->getNsText( $group->getNamespace() ); |
51 | 51 | |
52 | | - foreach ( $group->load( 'en' ) as $key => $definition ) { |
| 52 | + $definitions = $group->load( $group->getSourceLanguage() ); |
| 53 | + foreach ( $definitions as $key => $definition ) { |
53 | 54 | // TODO: would be nice to do key normalisation closer to the message groups, to avoid transforming back and forth. |
54 | 55 | // But how to preserve the original keys... |
55 | 56 | $key = strtr( $key, ' ', '_' ); |
— | — | @@ -75,7 +76,7 @@ |
76 | 77 | 'text' => $definition, |
77 | 78 | 'context' => "$ns_text:$key", |
78 | 79 | 'length' => strlen( $definition ), |
79 | | - 'lang' => 'en' |
| 80 | + 'lang' => $group->getSourceLanguage(), |
80 | 81 | ); |
81 | 82 | |
82 | 83 | $source_id = $dbw->selectField( '`sources`', 'sid', $insert, __METHOD__ ); |
Index: trunk/extensions/Translate/FFS.php |
— | — | @@ -8,7 +8,7 @@ |
9 | 9 | * @file |
10 | 10 | * @defgroup FFS File format support |
11 | 11 | * @author Niklas Laxström |
12 | | - * @copyright Copyright © 2008-2010, Niklas Laxström |
| 12 | + * @copyright Copyright © 2008-2011, Niklas Laxström |
13 | 13 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
14 | 14 | */ |
15 | 15 | |
— | — | @@ -89,7 +89,7 @@ |
90 | 90 | public function setWritePath( $writePath ) { $this->writePath = $writePath; } |
91 | 91 | public function getWritePath() { return $this->writePath; } |
92 | 92 | |
93 | | - public function exists( $code = 'en' ) { |
| 93 | + public function exists( $code ) { |
94 | 94 | $filename = $this->group->getSourceFilePath( $code ); |
95 | 95 | if ( $filename === null ) { |
96 | 96 | return false; |
— | — | @@ -1077,10 +1077,11 @@ |
1078 | 1078 | |
1079 | 1079 | public function write( MessageCollection $collection ) { |
1080 | 1080 | if ( $this->fw === null ) { |
1081 | | - $outputFile = $this->writePath . '/' . $this->group->getTargetFilename( 'en' ); |
| 1081 | + $sourceLanguage = $this->group->getSourceLanguage(); |
| 1082 | + $outputFile = $this->writePath . '/' . $this->group->getTargetFilename( $sourceLanguage ); |
1082 | 1083 | wfMkdirParents( dirname( $outputFile ), null, __METHOD__ ); |
1083 | 1084 | $this->fw = fopen( $outputFile, 'w' ); |
1084 | | - $this->fw = fopen( $this->writePath . '/' . $this->group->getTargetFilename( 'en' ), 'w' ); |
| 1085 | + $this->fw = fopen( $this->writePath . '/' . $this->group->getTargetFilename( $sourceLanguage ), 'w' ); |
1085 | 1086 | fwrite( $this->fw, "# -*- coding: utf-8 -*-\nmsg = {\n" ); |
1086 | 1087 | } |
1087 | 1088 | |
Index: trunk/extensions/Translate/MessageGroups.php |
— | — | @@ -5,7 +5,7 @@ |
6 | 6 | * |
7 | 7 | * @file |
8 | 8 | * @author Niklas Laxström |
9 | | - * @copyright Copyright © 2008-2010, Niklas Laxström |
| 9 | + * @copyright Copyright © 2008-2011, Niklas Laxström |
10 | 10 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
11 | 11 | */ |
12 | 12 | |
— | — | @@ -69,6 +69,10 @@ |
70 | 70 | public function isMeta() { return $this->meta; } |
71 | 71 | public function setMeta( $value ) { $this->meta = $value; } |
72 | 72 | |
| 73 | + public function getSourceLanguage() { |
| 74 | + return 'en'; |
| 75 | + } |
| 76 | + |
73 | 77 | /** |
74 | 78 | * To avoid key conflicts between groups or separated changed messages between |
75 | 79 | * branches one can set a message key mangler. |
— | — | @@ -113,7 +117,7 @@ |
114 | 118 | * @return Array of messages definitions indexed by key. |
115 | 119 | */ |
116 | 120 | public function getDefinitions() { |
117 | | - $defs = $this->load( 'en' ); |
| 121 | + $defs = $this->load( $this->getSourceLanguage() ); |
118 | 122 | if ( !is_array( $defs ) ) { |
119 | 123 | throw new MWException( "Unable to load definitions for " . $this->getLabel() ); |
120 | 124 | } |
— | — | @@ -244,6 +248,10 @@ |
245 | 249 | |
246 | 250 | return isset( $tags[$type] ) ? $tags[$type] : array(); |
247 | 251 | } |
| 252 | + |
| 253 | + protected function isSourceLanguage( $code ) { |
| 254 | + return $code === $this->getSourceLanguage(); |
| 255 | + } |
248 | 256 | } |
249 | 257 | |
250 | 258 | /** |
— | — | @@ -334,7 +342,7 @@ |
335 | 343 | ); |
336 | 344 | |
337 | 345 | if ( $this->parentId ) { |
338 | | - if ( $code !== 'en' ) { |
| 346 | + if ( !$this->isSourceLanguage( $code ) ) { |
339 | 347 | // For branches, load newer compatible messages for missing entries, if any. |
340 | 348 | $trunk = MessageGroups::getGroup( $this->parentId ); |
341 | 349 | $messages += $trunk->mangler->unmangle( $trunk->load( $code ) ); |
— | — | @@ -430,7 +438,7 @@ |
431 | 439 | } |
432 | 440 | |
433 | 441 | if ( $desc === null ) { |
434 | | - $desc = $this->getMessage( $key, 'en' ); |
| 442 | + $desc = $this->getMessage( $key, $this->getSourceLanguage() ); |
435 | 443 | } |
436 | 444 | |
437 | 445 | if ( $desc !== null ) { |
— | — | @@ -503,7 +511,7 @@ |
504 | 512 | } |
505 | 513 | |
506 | 514 | public function exists() { |
507 | | - return is_readable( $this->getMessageFileWithPath( 'en' ) ); |
| 515 | + return is_readable( $this->getMessageFileWithPath( $this->getSourceLanguage() ) ); |
508 | 516 | } |
509 | 517 | |
510 | 518 | public function getChecker() { |
— | — | @@ -543,7 +551,7 @@ |
544 | 552 | public function initCollection( $code, $unique = false ) { |
545 | 553 | $collection = parent::initCollection( $code, $unique ); |
546 | 554 | |
547 | | - $defs = $this->load( 'en' ); |
| 555 | + $defs = $this->load( $this->getSourceLanguage() ); |
548 | 556 | foreach ( $defs as $key => $value ) { |
549 | 557 | $collection[$key] = new FatMessage( $key, implode( ", ", $value ) ); |
550 | 558 | } |
— | — | @@ -628,7 +636,7 @@ |
629 | 637 | $data = file_get_contents( dirname( __FILE__ ) . '/wikimedia-mostused-2011.txt' ); |
630 | 638 | $data = str_replace( "\r", '', $data ); |
631 | 639 | $messages = explode( "\n", $data ); |
632 | | - $contents = Language::getMessagesFor( 'en' ); |
| 640 | + $contents = Language::getMessagesFor( $this->getSourceLanguage() ); |
633 | 641 | $definitions = array(); |
634 | 642 | |
635 | 643 | foreach ( $messages as $key ) { |
— | — | @@ -641,7 +649,6 @@ |
642 | 650 | } |
643 | 651 | } |
644 | 652 | |
645 | | - |
646 | 653 | /** |
647 | 654 | * Group for messages that can be controlled via a page in %MediaWiki namespace. |
648 | 655 | * |
— | — | @@ -666,6 +673,12 @@ |
667 | 674 | $this->source = $source; |
668 | 675 | } |
669 | 676 | |
| 677 | + /// Defaults to wiki content language. |
| 678 | + public function getSourceLanguage() { |
| 679 | + global $wgLanguagecode; |
| 680 | + return $wgLanguagecode; |
| 681 | + } |
| 682 | + |
670 | 683 | /** |
671 | 684 | * Fetch definitions from database. |
672 | 685 | * @return \array Array of messages keys with definitions. |
— | — | @@ -721,6 +734,12 @@ |
722 | 735 | $this->namespaces = array( NS_TRANSLATIONS, NS_TRANSLATIONS_TALK ); |
723 | 736 | } |
724 | 737 | |
| 738 | + /// Defaults to wiki content language. |
| 739 | + public function getSourceLanguage() { |
| 740 | + global $wgLanguagecode; |
| 741 | + return $wgLanguagecode; |
| 742 | + } |
| 743 | + |
725 | 744 | public function getTitle() { |
726 | 745 | if ( is_string( $this->title ) ) { |
727 | 746 | $this->title = Title::newFromText( $this->title ); |
— | — | @@ -757,7 +776,7 @@ |
758 | 777 | } |
759 | 778 | |
760 | 779 | public function load( $code ) { |
761 | | - if ( $code === 'en' ) { |
| 780 | + if ( $this->isSourceLanguage( $code ) ) { |
762 | 781 | return $this->getDefinitions(); |
763 | 782 | } |
764 | 783 | |
— | — | @@ -773,8 +792,8 @@ |
774 | 793 | * @return \mixed Stored translation or null. |
775 | 794 | */ |
776 | 795 | public function getMessage( $key, $code ) { |
777 | | - if ( $code === 'en' ) { |
778 | | - $stuff = $this->load( 'en' ); |
| 796 | + if ( $this->isSourceLanguage( $code ) ) { |
| 797 | + $stuff = $this->load( $code ); |
779 | 798 | return isset( $stuff[$key] ) ? $stuff[$key] : null; |
780 | 799 | } |
781 | 800 | |
Index: trunk/extensions/Translate/TranslateEditAddons.php |
— | — | @@ -6,7 +6,7 @@ |
7 | 7 | * @file |
8 | 8 | * @author Niklas Laxström |
9 | 9 | * @author Siebrand Mazeland |
10 | | - * @copyright Copyright © 2007-2010 Niklas Laxström, Siebrand Mazeland |
| 10 | + * @copyright Copyright © 2007-2011 Niklas Laxström, Siebrand Mazeland |
11 | 11 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
12 | 12 | */ |
13 | 13 | |
— | — | @@ -36,7 +36,7 @@ |
37 | 37 | return true; |
38 | 38 | } |
39 | 39 | |
40 | | - $collection = $group->initCollection( 'en' ); |
| 40 | + $collection = $group->initCollection( $group->getSourceLanguage() ); |
41 | 41 | $collection->filter( 'optional' ); |
42 | 42 | $keys = array_keys( $collection->keys() ); |
43 | 43 | $count = count( $keys ); |
— | — | @@ -370,7 +370,7 @@ |
371 | 371 | $checker = $group->getChecker(); |
372 | 372 | |
373 | 373 | if ( $checker ) { |
374 | | - $en = $group->getMessage( $key, 'en' ); |
| 374 | + $en = $group->getMessage( $key, $group->getSourceLanguage() ); |
375 | 375 | $message = new FatMessage( $key, $en ); |
376 | 376 | /** |
377 | 377 | * Take the contents from edit field as a translation. |
— | — | @@ -418,7 +418,9 @@ |
419 | 419 | return true; |
420 | 420 | } |
421 | 421 | |
422 | | - $definitionTitle = Title::makeTitleSafe( $title->getNamespace(), "$key/en" ); |
| 422 | + |
| 423 | + |
| 424 | + $definitionTitle = Title::makeTitleSafe( $title->getNamespace(), "$key/" . $group->getSourceLanguage() ); |
423 | 425 | if ( $definitionTitle && $definitionTitle->exists() ) { |
424 | 426 | $definitionRevision = $definitionTitle->getLatestRevID(); |
425 | 427 | |
Index: trunk/extensions/Translate/Translate.php |
— | — | @@ -15,7 +15,7 @@ |
16 | 16 | /** |
17 | 17 | * Version number used in extension credits and in other placed where needed. |
18 | 18 | */ |
19 | | -define( 'TRANSLATE_VERSION', '2011-06-24' ); |
| 19 | +define( 'TRANSLATE_VERSION', '2011-07-09' ); |
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Extension credits properties. |
Index: trunk/extensions/Translate/TranslateTasks.php |
— | — | @@ -263,6 +263,7 @@ |
264 | 264 | $server = $config['server']; |
265 | 265 | $port = $config['port']; |
266 | 266 | $timeout = $config['timeout-sync']; |
| 267 | + $sourceLanguage = $this->group->getSourceLanguage(); |
267 | 268 | |
268 | 269 | $this->collection = $this->group->initCollection( $code ); |
269 | 270 | $this->collection->setInfile( $this->group->load( $code ) ); |
— | — | @@ -282,7 +283,7 @@ |
283 | 284 | } |
284 | 285 | |
285 | 286 | $def = rawurlencode( $this->collection[$key]->definition() ); |
286 | | - $url = "$server:$port/tmserver/en/$code/unit/$def"; |
| 287 | + $url = "$server:$port/tmserver/$sourceLanguage/$code/unit/$def"; |
287 | 288 | $suggestions = Http::get( $url, $timeout ); |
288 | 289 | |
289 | 290 | if ( $suggestions !== false ) { |
Index: trunk/extensions/Translate/utils/TranslationHelpers.php |
— | — | @@ -132,7 +132,7 @@ |
133 | 133 | return; |
134 | 134 | } |
135 | 135 | |
136 | | - $this->definition = $this->group->getMessage( $this->page, 'en' ); |
| 136 | + $this->definition = $this->group->getMessage( $this->page, $this->group->getSourceLanguage() ); |
137 | 137 | |
138 | 138 | return $this->definition; |
139 | 139 | } |
— | — | @@ -641,10 +641,17 @@ |
642 | 642 | wfMsg( 'word-separator' ) . |
643 | 643 | wfMsg( 'parentheses', $title ); |
644 | 644 | |
| 645 | + // Source language object |
| 646 | + $sl = Language::factory( $this->group->getSourceLanguage() ); |
| 647 | + |
645 | 648 | $dialogID = $this->dialogID(); |
646 | 649 | $id = Sanitizer::escapeId( "def-$dialogID" ); |
647 | 650 | $msg = $this->adder( $id ) . "\n" . Html::rawElement( 'div', |
648 | | - array( 'class' => 'mw-translate-edit-deftext', 'dir' => 'ltr', 'lang' => 'en' ), |
| 651 | + array( |
| 652 | + 'class' => 'mw-translate-edit-deftext', |
| 653 | + 'dir' => $sl->getDir(), |
| 654 | + 'lang' => $sl->getCode(), |
| 655 | + ), |
649 | 656 | TranslateUtils::convertWhiteSpaceToHTML( $en ) |
650 | 657 | ); |
651 | 658 | |
— | — | @@ -825,7 +832,7 @@ |
826 | 833 | if ( $ffs instanceof GettextFFS ) { |
827 | 834 | global $wgContLang; |
828 | 835 | $mykey = $wgContLang->lcfirst( $this->page ); |
829 | | - $data = $ffs->read( 'en' ); |
| 836 | + $data = $ffs->read( $this->group->getSourceLanguage() ); |
830 | 837 | $help = $data['TEMPLATE'][$mykey]['comments']; |
831 | 838 | // Do not display an empty comment. That's no help and takes up unnecessary space. |
832 | 839 | $conf = $this->group->getConfiguration(); |
Index: trunk/extensions/Translate/Groups.php |
— | — | @@ -4,7 +4,7 @@ |
5 | 5 | * |
6 | 6 | * @file |
7 | 7 | * @author Niklas Laxström |
8 | | - * @copyright Copyright © 2010, Niklas Laxström |
| 8 | + * @copyright Copyright © 2010-2011, Niklas Laxström |
9 | 9 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
10 | 10 | */ |
11 | 11 | |
— | — | @@ -106,6 +106,12 @@ |
107 | 107 | * @return string or null |
108 | 108 | */ |
109 | 109 | public function getMessage( $key, $code ); |
| 110 | + |
| 111 | + /** |
| 112 | + * Returns language code depicting the language of source text. |
| 113 | + * @return string |
| 114 | + */ |
| 115 | + public function getSourceLanguage(); |
110 | 116 | } |
111 | 117 | |
112 | 118 | /** |
— | — | @@ -137,6 +143,11 @@ |
138 | 144 | |
139 | 145 | public function isMeta() { return $this->getFromConf( 'BASIC', 'meta' ); } |
140 | 146 | |
| 147 | + public function getSourceLanguage() { |
| 148 | + $conf = $this->getFromConf( 'BASIC', 'sourcelanguage' ); |
| 149 | + return $conf !== 'null' ? $conf : 'en'; |
| 150 | + } |
| 151 | + |
141 | 152 | protected function getFromConf( $section, $key ) { |
142 | 153 | return isset( $this->conf[$section][$key] ) ? $this->conf[$section][$key] : null; |
143 | 154 | } |
— | — | @@ -211,7 +222,7 @@ |
212 | 223 | $cache = new MessageGroupCache( $this ); |
213 | 224 | if ( !$cache->exists() ) { |
214 | 225 | wfWarn( "By-passing message group cache" ); |
215 | | - $messages = $this->load( 'en' ); |
| 226 | + $messages = $this->load( $this->getSourceLanguage() ); |
216 | 227 | } else { |
217 | 228 | foreach ( $cache->getKeys() as $key ) { |
218 | 229 | $messages[$key] = $cache->get( $key ); |
— | — | @@ -266,7 +277,7 @@ |
267 | 278 | |
268 | 279 | if ( !$cache->exists() ) { |
269 | 280 | wfWarn( "By-passing message group cache" ); |
270 | | - $messageKeys = array_keys( $this->load( 'en' ) ); |
| 281 | + $messageKeys = array_keys( $this->load( $this->getSourceLanguage() ) ); |
271 | 282 | } else { |
272 | 283 | $messageKeys = $cache->getKeys(); |
273 | 284 | } |
— | — | @@ -346,6 +357,10 @@ |
347 | 358 | |
348 | 359 | return $index; |
349 | 360 | } |
| 361 | + |
| 362 | + protected function isSourceLanguage( $code ) { |
| 363 | + return $code === $this->getSourceLanguage(); |
| 364 | + } |
350 | 365 | } |
351 | 366 | |
352 | 367 | /** |
— | — | @@ -390,7 +405,7 @@ |
391 | 406 | } |
392 | 407 | |
393 | 408 | public function getSourceFilePath( $code ) { |
394 | | - if ( $code === 'en' ) { |
| 409 | + if ( $this->isSourceLanguage( $code ) ) { |
395 | 410 | $pattern = $this->getFromConf( 'FILES', 'definitionFile' ); |
396 | 411 | if ( $pattern !== null ) { |
397 | 412 | return $this->replaceVariables( $pattern, $code ); |
— | — | @@ -610,7 +625,7 @@ |
611 | 626 | } |
612 | 627 | } else { |
613 | 628 | // BC for MessageGroupOld |
614 | | - $messages += $group->load( 'en' ); |
| 629 | + $messages += $group->load( $this->getSourceLanguage() ); |
615 | 630 | } |
616 | 631 | } |
617 | 632 | |