Remove duplication of Langauge digitTransformTable in javascript.
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderLanguageDataModule.php
index 4904735..a36aaec 100644 (file)
  */
 class ResourceLoaderLanguageDataModule extends ResourceLoaderModule {
 
+       protected $language;
        /**
         * Get the grammer forms for the site content language.
         *
         * @return array
         */
        protected function getSiteLangGrammarForms() {
-               global $wgContLang;
-               return $wgContLang->getGrammarForms();
+               return $this->language->getGrammarForms();
+       }
+
+       /**
+        * Get the digit transform table for the content language
+        * Seperator transform table also required here to convert
+        * the . and , sign to appropriate forms in content language.
+        *
+        * @return array
+        */
+       protected function getDigitTransformTable() {
+               $digitTransformTable = $this->language->digitTransformTable();
+               $separatorTransformTable = $this->language->separatorTransformTable();
+               if ( $digitTransformTable ) {
+                       array_merge( $digitTransformTable, (array)$separatorTransformTable );
+               } else {
+                       return $separatorTransformTable;
+               }
+               return $digitTransformTable;
+       }
+
+       /**
+        * Get all the dynamic data for the content language to an array
+        *
+        * @return array
+        */
+       protected function getData() {
+               return array( 'grammarForms' => $this->getSiteLangGrammarForms(),
+                               'digitTransformTable' => $this->getDigitTransformTable()
+                       );
        }
 
        /**
@@ -42,11 +71,10 @@ class ResourceLoaderLanguageDataModule extends ResourceLoaderModule {
         * @return string: Javascript code
         */
        public function getScript( ResourceLoaderContext $context ) {
-               global $wgContLang;
-
+               $this->language = Language::factory( $context ->getLanguage() );
                return Xml::encodeJsCall( 'mw.language.setData', array(
-                       $wgContLang->getCode(),
-                       array( 'grammarForms' => $this->getSiteLangGrammarForms() )
+                       $this->language->getCode(),
+                       $this->getData()
                ) );
        }
 
@@ -55,11 +83,12 @@ class ResourceLoaderLanguageDataModule extends ResourceLoaderModule {
         * @return array|int|Mixed
         */
        public function getModifiedTime( ResourceLoaderContext $context ) {
+               $this->language = Language::factory( $context ->getLanguage() );
                $cache = wfGetCache( CACHE_ANYTHING );
                $key = wfMemcKey( 'resourceloader', 'langdatamodule', 'changeinfo' );
 
-               $forms = $this->getSiteLangGrammarForms();
-               $hash = md5( serialize( $forms ) );
+               $data = $this->getData();
+               $hash = md5( serialize( $data ) );
 
                $result = $cache->get( $key );
                if ( is_array( $result ) && $result['hash'] === $hash ) {