MediaWiki uses a number of nonstandard codes which do not validate
according to the IANA language subtag registry. Some of them have
the wrong semantics entirely: MediaWiki's `sr-ec` variant maps to
BCP 47 `sr-EC` which is "Serbian as used in Ethiopia" (!).
Extend LanguageCode::bcp47() to map our nonstandard codes to valid
BCP 47 language codes. Export the mapping so that it can be used
in JavaScript's corresponding mw.language.bcp47() implementation
as well.
Thanks to TheDJ (I10b4473c7e53f027812bbccf26bb47aec15fddfd) and
Fomafix (I93efc190714ba76247d30ba49fc21ae872fc3555) for previous
attempts at this!
Also removed a fixme for the name of 'Twi', dating back to 2004
(f59c3be23b) -- checking
tw.wikipedia.org it certainly appears that the autonym of 'Twi'
is correctly 'Twi'.
Tracking bugs for invalid language codes are T125073 and T145535.
Discussion of zh-XX => zh-HanX-XX mapping is at T198419.
Bug: T34483
Bug: T106367
Bug: T120847
Change-Id: I807dd55d49e9bd19443329231326a5b0d3e6c453
83 lines
2.5 KiB
PHP
83 lines
2.5 KiB
PHP
<?php
|
|
/**
|
|
* ResourceLoader module for populating language specific data.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
*
|
|
* @file
|
|
* @author Santhosh Thottingal
|
|
* @author Timo Tijhof
|
|
*/
|
|
|
|
/**
|
|
* ResourceLoader module for populating language specific data, such as grammar forms.
|
|
*/
|
|
class ResourceLoaderLanguageDataModule extends ResourceLoaderFileModule {
|
|
|
|
protected $targets = [ 'desktop', 'mobile' ];
|
|
|
|
/**
|
|
* Get all the dynamic data for the content language to an array.
|
|
*
|
|
* @param ResourceLoaderContext $context
|
|
* @return array
|
|
*/
|
|
protected function getData( ResourceLoaderContext $context ) {
|
|
$language = Language::factory( $context->getLanguage() );
|
|
return [
|
|
'digitTransformTable' => $language->digitTransformTable(),
|
|
'separatorTransformTable' => $language->separatorTransformTable(),
|
|
'minimumGroupingDigits' => $language->minimumGroupingDigits(),
|
|
'grammarForms' => $language->getGrammarForms(),
|
|
'grammarTransformations' => $language->getGrammarTransformations(),
|
|
'pluralRules' => $language->getPluralRules(),
|
|
'digitGroupingPattern' => $language->digitGroupingPattern(),
|
|
'fallbackLanguages' => $language->getFallbackLanguages(),
|
|
'bcp47Map' => LanguageCode::getNonstandardLanguageCodeMapping(),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @param ResourceLoaderContext $context
|
|
* @return string JavaScript code
|
|
*/
|
|
public function getScript( ResourceLoaderContext $context ) {
|
|
$fileScript = parent::getScript( $context );
|
|
$langDataScript = Xml::encodeJsCall(
|
|
'mw.language.setData',
|
|
[
|
|
$context->getLanguage(),
|
|
$this->getData( $context )
|
|
],
|
|
ResourceLoader::inDebugMode()
|
|
);
|
|
return $fileScript . $langDataScript;
|
|
}
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
public function enableModuleContentVersion() {
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
public function supportsURLLoading() {
|
|
return false;
|
|
}
|
|
}
|