output: Narrow Title type hint to LinkTarget
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderLanguageDataModule.php
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 * @author Santhosh Thottingal
20 */
21
22 /**
23 * ResourceLoader module for populating language specific data, such as grammar forms.
24 */
25 class ResourceLoaderLanguageDataModule extends ResourceLoaderFileModule {
26
27 protected $targets = [ 'desktop', 'mobile' ];
28
29 /**
30 * Get all the dynamic data for the content language to an array.
31 *
32 * @param ResourceLoaderContext $context
33 * @return array
34 */
35 protected function getData( ResourceLoaderContext $context ) {
36 $language = Language::factory( $context->getLanguage() );
37 return [
38 'digitTransformTable' => $language->digitTransformTable(),
39 'separatorTransformTable' => $language->separatorTransformTable(),
40 'minimumGroupingDigits' => $language->minimumGroupingDigits(),
41 'grammarForms' => $language->getGrammarForms(),
42 'grammarTransformations' => $language->getGrammarTransformations(),
43 'pluralRules' => $language->getPluralRules(),
44 'digitGroupingPattern' => $language->digitGroupingPattern(),
45 'fallbackLanguages' => $language->getFallbackLanguages(),
46 'bcp47Map' => LanguageCode::getNonstandardLanguageCodeMapping(),
47 ];
48 }
49
50 /**
51 * @param ResourceLoaderContext $context
52 * @return string JavaScript code
53 */
54 public function getScript( ResourceLoaderContext $context ) {
55 $fileScript = parent::getScript( $context );
56 $langDataScript = Xml::encodeJsCall(
57 'mw.language.setData',
58 [
59 $context->getLanguage(),
60 $this->getData( $context )
61 ],
62 ResourceLoader::inDebugMode()
63 );
64 return $fileScript . $langDataScript;
65 }
66
67 /**
68 * @return bool
69 */
70 public function enableModuleContentVersion() {
71 return true;
72 }
73
74 /**
75 * @return bool
76 */
77 public function supportsURLLoading() {
78 return false;
79 }
80 }