3 * Resource loader module for populating language specific data.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @author Santhosh Thottingal
26 * ResourceLoader module for populating language specific data.
28 class ResourceLoaderLanguageDataModule
extends ResourceLoaderModule
{
31 protected $targets = array( 'desktop', 'mobile' );
33 * Get the grammar forms for the site content language.
37 protected function getSiteLangGrammarForms() {
38 return $this->language
->getGrammarForms();
42 * Get the plural forms for the site content language.
46 protected function getPluralRules() {
47 return $this->language
->getPluralRules();
51 * Get the digit groupin Pattern for the site content language.
55 protected function getDigitGroupingPattern() {
56 return $this->language
->digitGroupingPattern();
60 * Get the digit transform table for the content language
64 protected function getDigitTransformTable() {
65 return $this->language
->digitTransformTable();
69 * Get seperator transform table required for converting
70 * the . and , sign to appropriate forms in site content language.
74 protected function getSeparatorTransformTable() {
75 return $this->language
->separatorTransformTable();
80 * Get all the dynamic data for the content language to an array
84 protected function getData() {
86 'digitTransformTable' => $this->getDigitTransformTable(),
87 'separatorTransformTable' => $this->getSeparatorTransformTable(),
88 'grammarForms' => $this->getSiteLangGrammarForms(),
89 'pluralRules' => $this->getPluralRules(),
90 'digitGroupingPattern' => $this->getDigitGroupingPattern(),
95 * @param $context ResourceLoaderContext
96 * @return string: JavaScript code
98 public function getScript( ResourceLoaderContext
$context ) {
99 $this->language
= Language
::factory( $context->getLanguage() );
100 return Xml
::encodeJsCall( 'mw.language.setData', array(
101 $this->language
->getCode(),
107 * @param $context ResourceLoaderContext
108 * @return array|int|Mixed
110 public function getModifiedTime( ResourceLoaderContext
$context ) {
111 $this->language
= Language
::factory( $context->getLanguage() );
112 $cache = wfGetCache( CACHE_ANYTHING
);
113 $key = wfMemcKey( 'resourceloader', 'langdatamodule', 'changeinfo' );
115 $data = $this->getData();
116 $hash = md5( serialize( $data ) );
118 $result = $cache->get( $key );
119 if ( is_array( $result ) && $result['hash'] === $hash ) {
120 return $result['timestamp'];
122 $timestamp = wfTimestamp();
123 $cache->set( $key, array(
125 'timestamp' => $timestamp,
133 public function getDependencies() {
134 return array( 'mediawiki.language.init' );