2012-04-02 13:01:10 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2012-04-30 07:16:10 +00:00
|
|
|
* Resource loader module for populating language specific data.
|
|
|
|
|
*
|
2012-04-02 13:01:10 +00:00
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
class ResourceLoaderLanguageDataModule extends ResourceLoaderModule {
|
|
|
|
|
|
2012-12-17 20:32:19 +00:00
|
|
|
protected $targets = array( 'desktop', 'mobile' );
|
2013-01-18 15:34:54 +00:00
|
|
|
|
2012-06-06 06:12:12 +00:00
|
|
|
/**
|
2013-08-30 00:31:37 +00:00
|
|
|
* Get all the dynamic data for the content language to an array.
|
|
|
|
|
*
|
2014-04-30 21:45:13 +00:00
|
|
|
* @param ResourceLoaderContext $context
|
2012-06-06 06:12:12 +00:00
|
|
|
* @return array
|
|
|
|
|
*/
|
2014-04-30 21:45:13 +00:00
|
|
|
protected function getData( ResourceLoaderContext $context ) {
|
|
|
|
|
$language = Language::factory( $context->getLanguage() );
|
2012-06-18 08:28:44 +00:00
|
|
|
return array(
|
2014-04-30 21:45:13 +00:00
|
|
|
'digitTransformTable' => $language->digitTransformTable(),
|
|
|
|
|
'separatorTransformTable' => $language->separatorTransformTable(),
|
|
|
|
|
'grammarForms' => $language->getGrammarForms(),
|
|
|
|
|
'pluralRules' => $language->getPluralRules(),
|
|
|
|
|
'digitGroupingPattern' => $language->digitGroupingPattern(),
|
2014-08-09 00:14:09 +00:00
|
|
|
'fallbackLanguages' => $language->getFallbackLanguages(),
|
2012-06-18 08:28:44 +00:00
|
|
|
);
|
2012-04-02 13:01:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-04-20 21:33:05 +00:00
|
|
|
* @param ResourceLoaderContext $context
|
|
|
|
|
* @return string JavaScript code
|
2012-04-02 13:01:10 +00:00
|
|
|
*/
|
|
|
|
|
public function getScript( ResourceLoaderContext $context ) {
|
2014-12-19 16:55:46 +00:00
|
|
|
return Xml::encodeJsCall(
|
|
|
|
|
'mw.language.setData',
|
|
|
|
|
array(
|
|
|
|
|
$context->getLanguage(),
|
|
|
|
|
$this->getData( $context )
|
|
|
|
|
),
|
|
|
|
|
ResourceLoader::inDebugMode()
|
|
|
|
|
);
|
2012-04-02 13:01:10 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-30 00:31:37 +00:00
|
|
|
/**
|
2014-04-20 21:33:05 +00:00
|
|
|
* @param ResourceLoaderContext $context
|
|
|
|
|
* @return string Hash
|
2013-08-30 00:31:37 +00:00
|
|
|
*/
|
|
|
|
|
public function getModifiedHash( ResourceLoaderContext $context ) {
|
2014-04-30 21:45:13 +00:00
|
|
|
return md5( serialize( $this->getData( $context ) ) );
|
2012-04-02 13:01:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-04-08 21:34:08 +00:00
|
|
|
* @param ResourceLoaderContext $context
|
2012-04-02 13:01:10 +00:00
|
|
|
* @return array
|
|
|
|
|
*/
|
2015-04-08 21:34:08 +00:00
|
|
|
public function getDependencies( ResourceLoaderContext $context = null ) {
|
2012-06-05 22:58:54 +00:00
|
|
|
return array( 'mediawiki.language.init' );
|
2012-04-02 13:01:10 +00:00
|
|
|
}
|
|
|
|
|
}
|