Index: branches/jsgrammar/includes/resourceloader/ResourceLoaderLanguageModule.php |
— | — | @@ -0,0 +1,74 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * This program is free software; you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation; either version 2 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License along |
| 15 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 16 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | + * http://www.gnu.org/copyleft/gpl.html |
| 18 | + * |
| 19 | + * @file |
| 20 | + * @author Santhosh Thottingal |
| 21 | + * @author Timo Tijhof |
| 22 | + */ |
| 23 | + |
| 24 | +/** |
| 25 | + * ResourceLoader module for generating language specific scripts/css. |
| 26 | + */ |
| 27 | +class ResourceLoaderLanguageModule extends ResourceLoaderModule { |
| 28 | + |
| 29 | + /** |
| 30 | + * Get the grammer forms for the site content language. |
| 31 | + * |
| 32 | + * @return Array |
| 33 | + */ |
| 34 | + protected function getSiteLangGrammarForms( ) { |
| 35 | + global $wgContLang; |
| 36 | + return $wgContLang->getGrammarForms(); |
| 37 | + } |
| 38 | + /** |
| 39 | + * @param $context ResourceLoaderContext |
| 40 | + * @return string |
| 41 | + */ |
| 42 | + public function getScript( ResourceLoaderContext $context ) { |
| 43 | + global $wgContLang; |
| 44 | + $js = |
| 45 | + 'var langCode = ' . FormatJson::encode( $wgContLang->getCode() ) . ', ' . |
| 46 | + "langData = mw.language.data;\n" . |
| 47 | + "if ( langData[langCode] === undefined ) {\n" . |
| 48 | + " langData[langCode] = new mw.Map();\n" . |
| 49 | + "}\n" . |
| 50 | + Xml::encodeJsCall( 'langData[langCode].set', |
| 51 | + array( 'grammarForms', $this->getSiteLangGrammarForms( ) ) |
| 52 | + ); |
| 53 | + return $js; |
| 54 | + } |
| 55 | + /** |
| 56 | + * @param $context ResourceLoaderContext |
| 57 | + * @return array|int|Mixed |
| 58 | + */ |
| 59 | + public function getModifiedTime( ResourceLoaderContext $context ) { |
| 60 | + global $wgCacheEpoch; |
| 61 | + /* |
| 62 | + global $wgContLang, $wgCacheEpoch; |
| 63 | + return max( $wgCacheEpoch, $wgContLang->getLastModified() ); |
| 64 | + */ |
| 65 | + |
| 66 | + return $wgCacheEpoch; |
| 67 | + } |
| 68 | + /** |
| 69 | + * @return array |
| 70 | + */ |
| 71 | + public function getDependencies() { |
| 72 | + return array( 'mediawiki.language' ); |
| 73 | + } |
| 74 | +} |
| 75 | + |
Property changes on: branches/jsgrammar/includes/resourceloader/ResourceLoaderLanguageModule.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 76 | + native |
Index: branches/jsgrammar/includes/AutoLoader.php |
— | — | @@ -732,6 +732,7 @@ |
733 | 733 | 'ResourceLoaderUserModule' => 'includes/resourceloader/ResourceLoaderUserModule.php', |
734 | 734 | 'ResourceLoaderUserOptionsModule' => 'includes/resourceloader/ResourceLoaderUserOptionsModule.php', |
735 | 735 | 'ResourceLoaderUserTokensModule' => 'includes/resourceloader/ResourceLoaderUserTokensModule.php', |
| 736 | + 'ResourceLoaderLanguageModule' => 'includes/resourceloader/ResourceLoaderLanguageModule.php', |
736 | 737 | 'ResourceLoaderWikiModule' => 'includes/resourceloader/ResourceLoaderWikiModule.php', |
737 | 738 | |
738 | 739 | # includes/revisiondelete |
Index: branches/jsgrammar/languages/Language.php |
— | — | @@ -3239,8 +3239,18 @@ |
3240 | 3240 | } |
3241 | 3241 | return $forms; |
3242 | 3242 | } |
3243 | | - |
3244 | 3243 | /** |
| 3244 | + * Get the grammar forms for the content language |
| 3245 | + * @return array of grammar forms |
| 3246 | + */ |
| 3247 | + function getGrammarForms( ) { |
| 3248 | + global $wgGrammarForms; |
| 3249 | + if ( isset( $wgGrammarForms[$this->getCode()] ) && is_array( $wgGrammarForms[$this->getCode()] ) ) { |
| 3250 | + return $wgGrammarForms[$this->getCode()]; |
| 3251 | + } |
| 3252 | + return array(); |
| 3253 | + } |
| 3254 | + /** |
3245 | 3255 | * @todo Maybe translate block durations. Note that this function is somewhat misnamed: it |
3246 | 3256 | * deals with translating the *duration* ("1 week", "4 days", etc), not the expiry time |
3247 | 3257 | * (which is an absolute timestamp). Please note: do NOT add this blindly, as it is used |
Index: branches/jsgrammar/resources/Resources.php |
— | — | @@ -12,6 +12,7 @@ |
13 | 13 | 'user.options' => array( 'class' => 'ResourceLoaderUserOptionsModule' ), |
14 | 14 | 'user.cssprefs' => array( 'class' => 'ResourceLoaderUserCSSPrefsModule' ), |
15 | 15 | 'user.tokens' => array( 'class' => 'ResourceLoaderUserTokensModule' ), |
| 16 | + 'language' => array( 'class' => 'ResourceLoaderLanguageModule' ), |
16 | 17 | 'filepage' => array( 'class' => 'ResourceLoaderFilePageModule' ), |
17 | 18 | |
18 | 19 | /* Skins */ |