Index: trunk/phase3/includes/GlobalFunctions.php |
— | — | @@ -2479,16 +2479,29 @@ |
2480 | 2480 | * Load an extension messages file |
2481 | 2481 | * |
2482 | 2482 | * @param string $extensionName Name of extension to load messages from\for. |
2483 | | - * @param boolean $all Whether or not to load all languages. |
| 2483 | + * @param string $langcode Language to load messages for, or false for default |
| 2484 | + * behvaiour (en, content language and user language). |
2484 | 2485 | */ |
2485 | | -function wfLoadExtensionMessages( $extensionName, $all = false ) { |
2486 | | - global $wgExtensionMessagesFiles, $wgMessageCache; |
2487 | | - if ( !empty( $wgExtensionMessagesFiles[$extensionName] ) ) { |
2488 | | - $wgMessageCache->loadMessagesFile( $wgExtensionMessagesFiles[$extensionName], $all ); |
2489 | | - // Prevent double-loading if all the messages have been loaded. |
2490 | | - if( $all ) { |
2491 | | - $wgExtensionMessagesFiles[$extensionName] = false; |
2492 | | - } |
| 2486 | +function wfLoadExtensionMessages( $extensionName, $langcode = false ) { |
| 2487 | + global $wgExtensionMessagesFiles, $wgMessageCache, $wgLang, $wgContLang; |
| 2488 | + |
| 2489 | + #For recording whether extension message files have been loaded in a given language. |
| 2490 | + static $loaded = array(); |
| 2491 | + |
| 2492 | + if( !$langcode && !array_key_exists( '*', $loaded ) ) { |
| 2493 | + # Just do en, content language and user language. |
| 2494 | + $wgMessageCache->loadMessagesFile( $wgExtensionMessagesFiles[$extensionName], false ); |
| 2495 | + # Mark that they have been loaded. |
| 2496 | + $loaded['en'] = true; |
| 2497 | + $loaded[$wgLang->getCode()] = true; |
| 2498 | + $loaded[$wgContLang->getCode()] = true; |
| 2499 | + # Mark that this part has been done to avoid weird if statements. |
| 2500 | + $loaded['*'] = true; |
| 2501 | + } elseif( is_string( $langcode ) && !array_key_exists( $langcode, $loaded ) ) { |
| 2502 | + # Load messages for specified language. |
| 2503 | + $wgMessageCache->loadMessagesFile( $wgExtensionMessagesFiles[$extensionName], $langcode ); |
| 2504 | + # Mark that they have been loaded. |
| 2505 | + $loaded[$langcode] = true; |
2493 | 2506 | } |
2494 | 2507 | } |
2495 | 2508 | |
Index: trunk/phase3/includes/MessageCache.php |
— | — | @@ -714,21 +714,21 @@ |
715 | 715 | * Load messages from a given file |
716 | 716 | * |
717 | 717 | * @param string $filename Filename of file to load. |
718 | | - * @param boolean $all Whether or not to load all languages. |
| 718 | + * @param string $langcode Language to load messages for, or false for |
| 719 | + * default behvaiour (en, content language and user |
| 720 | + * language). |
719 | 721 | */ |
720 | | - function loadMessagesFile( $filename, $all = false ) { |
| 722 | + function loadMessagesFile( $filename, $langcode = false ) { |
721 | 723 | global $wgLang, $wgContLang; |
722 | 724 | $messages = $magicWords = false; |
723 | 725 | require( $filename ); |
724 | 726 | |
725 | | - if( $all ) { |
726 | | - # Load all messages, regardless of language. |
727 | | - $validCodes = array_keys( Language::getLanguageNames() ); |
728 | | - foreach( $messages as $code => $array ) { |
729 | | - if( in_array( $code, $validCodes ) ) { |
730 | | - $this->processMessagesArray( $messages, $code ); |
731 | | - } |
732 | | - } |
| 727 | + $validCodes = Language::getLanguageNames(); |
| 728 | + if( is_string( $langcode ) && array_key_exists( $langcode, $validCodes ) ) { |
| 729 | + # Load messages for given language code. |
| 730 | + $this->processMessagesArray( $messages, $langcode ); |
| 731 | + } elseif( is_string( $langcode ) && !array_key_exists( $langcode, $validCodes ) ) { |
| 732 | + wfDebug( "Invalid language '$langcode' code passed to MessageCache::loadMessagesFile()" ); |
733 | 733 | } else { |
734 | 734 | # Load only languages that are usually used, and merge all |
735 | 735 | # fallbacks, except English. |
— | — | @@ -748,10 +748,10 @@ |
749 | 749 | * Process an array of messages, loading it into the message cache. |
750 | 750 | * |
751 | 751 | * @param array $messages Messages array. |
752 | | - * @param string $language Language code to process. |
| 752 | + * @param string $langcode Language code to process. |
753 | 753 | */ |
754 | | - function processMessagesArray( $messages, $language ) { |
755 | | - $fallbackCode = $language; |
| 754 | + function processMessagesArray( $messages, $langcode ) { |
| 755 | + $fallbackCode = $langcode; |
756 | 756 | $mergedMessages = array(); |
757 | 757 | do { |
758 | 758 | if ( isset($messages[$fallbackCode]) ) { |
— | — | @@ -761,7 +761,7 @@ |
762 | 762 | } while( $fallbackCode && $fallbackCode !== 'en' ); |
763 | 763 | |
764 | 764 | if ( !empty($mergedMessages) ) |
765 | | - $this->addMessages( $mergedMessages, $language ); |
| 765 | + $this->addMessages( $mergedMessages, $langcode ); |
766 | 766 | } |
767 | 767 | |
768 | 768 | } |