3 * Base language object with methods related to language support, attempting to mirror some of the
4 * functionality of the Language class in MediaWiki:
6 * - storing and retrieving language data
7 * - transforming message syntax (`{{PLURAL:}}`, `{{GRAMMAR:}}`, `{{GENDER:}}`)
15 * Language-related data (keyed by language, contains instances of mw.Map).
16 * Loaded dynamically (see ResourceLoaderLanguageDataModule class in PHP, registered
17 * as mediawiki.language.data on the client).
21 * // Override, extend or create the language data object of 'nl'
22 * mw.language.setData( 'nl', 'myKey', 'My value' );
24 * // Set multiple key/values pairs at once
25 * mw.language.setData( 'nl', { foo: 'X', bar: 'Y' } );
27 * To get GrammarForms data for language 'nl':
29 * var grammarForms = mw.language.getData( 'nl', 'grammarForms' );
33 * - `digitTransformTable`
34 * - `separatorTransformTable`
37 * - `digitGroupingPattern`
38 * - `fallbackLanguages`
45 * Convenience method for retrieving language data.
47 * Structured by language code and data key, covering for the potential inexistence of a
48 * data object for this language.
50 * @param {string} langCode
51 * @param {string} dataKey
52 * @return {Mixed} Value stored in the mw.Map (or `undefined` if there is no map for the
55 getData: function ( langCode, dataKey ) {
56 var langData = mw.language.data;
57 langCode = langCode.toLowerCase();
58 if ( langData && langData[ langCode ] instanceof mw.Map ) {
59 return langData[ langCode ].get( dataKey );
65 * Convenience method for setting language data.
67 * Creates the data mw.Map if there isn't one for the specified language already.
69 * @param {string} langCode
70 * @param {string|Object} dataKey Key or object of key/values
71 * @param {Mixed} [value] Value for dataKey, omit if dataKey is an object
73 setData: function ( langCode, dataKey, value ) {
74 var langData = mw.language.data;
75 langCode = langCode.toLowerCase();
76 if ( !( langData[ langCode ] instanceof mw.Map ) ) {
77 langData[ langCode ] = new mw.Map();
79 langData[ langCode ].set( dataKey, value );