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();
79 * Get all the dynamic data for the content language to an array.
81 * NOTE: Before calling this you HAVE to make sure $this->language is set.
85 protected function getData() {
87 'digitTransformTable' => $this->getDigitTransformTable(),
88 'separatorTransformTable' => $this->getSeparatorTransformTable(),
89 'grammarForms' => $this->getSiteLangGrammarForms(),
90 'pluralRules' => $this->getPluralRules(),
91 'digitGroupingPattern' => $this->getDigitGroupingPattern(),
96 * @param ResourceLoaderContext $context
97 * @return string JavaScript code
99 public function getScript( ResourceLoaderContext
$context ) {
100 $this->language
= Language
::factory( $context->getLanguage() );
101 return Xml
::encodeJsCall( 'mw.language.setData', array(
102 $this->language
->getCode(),
108 * @param ResourceLoaderContext $context
109 * @return int UNIX timestamp
111 public function getModifiedTime( ResourceLoaderContext
$context ) {
112 return max( 1, $this->getHashMtime( $context ) );
116 * @param ResourceLoaderContext $context
117 * @return string Hash
119 public function getModifiedHash( ResourceLoaderContext
$context ) {
120 $this->language
= Language
::factory( $context->getLanguage() );
122 return md5( serialize( $this->getData() ) );
128 public function getDependencies() {
129 return array( 'mediawiki.language.init' );