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`
44 * Convenience method for retrieving language data.
46 * Structured by language code and data key, covering for the potential inexistence of a
47 * data object for this language.
49 * @param {string} langCode
50 * @param {string} dataKey
51 * @return {Mixed} Value stored in the mw.Map (or `undefined` if there is no map for the
54 getData: function ( langCode, dataKey ) {
55 var langData = mw.language.data;
56 if ( langData && langData[langCode] instanceof mw.Map ) {
57 return langData[langCode].get( dataKey );
63 * Convenience method for setting language data.
65 * Creates the data mw.Map if there isn't one for the specified language already.
67 * @param {string} langCode
68 * @param {string|Object} dataKey Key or object of key/values
69 * @param {Mixed} [value] Value for dataKey, omit if dataKey is an object
71 setData: function ( langCode, dataKey, value ) {
72 var langData = mw.language.data;
73 if ( !( langData[langCode] instanceof mw.Map ) ) {
74 langData[langCode] = new mw.Map();
76 langData[langCode].set( dataKey, value );