MediaWiki  master
LanguageDataModule.php
Go to the documentation of this file.
1 <?php
22 namespace MediaWiki\ResourceLoader;
23 
24 use LanguageCode;
26 
34  protected $targets = [ 'desktop', 'mobile' ];
35 
43  public static function getData( $langCode ): array {
44  $language = MediaWikiServices::getInstance()->getLanguageFactory()
45  ->getLanguage( $langCode );
46  return [
47  'digitTransformTable' => $language->digitTransformTable(),
48  'separatorTransformTable' => $language->separatorTransformTable(),
49  'minimumGroupingDigits' => $language->minimumGroupingDigits(),
50  'grammarForms' => $language->getGrammarForms(),
51  'grammarTransformations' => $language->getGrammarTransformations(),
52  'pluralRules' => $language->getPluralRules(),
53  'digitGroupingPattern' => $language->digitGroupingPattern(),
54  'fallbackLanguages' => $language->getFallbackLanguages(),
56  ];
57  }
58 
63  public function getScript( Context $context ) {
64  return parent::getScript( $context )
65  . 'mw.language.setData('
66  . $context->encodeJson( $context->getLanguage() ) . ','
67  . $context->encodeJson( self::getData( $context->getLanguage() ) )
68  . ');';
69  }
70 
74  public function enableModuleContentVersion() {
75  return true;
76  }
77 
81  public function supportsURLLoading() {
82  return false;
83  }
84 }
85 
87 class_alias( LanguageDataModule::class, 'ResourceLoaderLanguageDataModule' );
Methods for dealing with language codes.
static getNonstandardLanguageCodeMapping()
Returns a mapping of non-standard language codes used by (current and previous version of) MediaWiki,...
Service locator for MediaWiki core services.
Context object that contains information about the state of a specific ResourceLoader web request.
Definition: Context.php:46
encodeJson( $data)
Wrapper around json_encode that avoids needless escapes, and pretty-prints in debug mode.
Definition: Context.php:493
Module based on local JavaScript/CSS files.
Definition: FileModule.php:53
Module for populating language specific data, such as grammar forms.
static getData( $langCode)
Get all the dynamic data for the content language to an array.