Merge "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 return parent::getScript( $context )
56 . 'mw.language.setData('
57 . ResourceLoader::encodeJsonForScript( $context->getLanguage() ) . ','
58 . ResourceLoader::encodeJsonForScript( $this->getData( $context ) )
59 . ');';
60 }
61
62 /**
63 * @return bool
64 */
65 public function enableModuleContentVersion() {
66 return true;
67 }
68
69 /**
70 * @return bool
71 */
72 public function supportsURLLoading() {
73 return false;
74 }
75 }