3 * Methods for transforming message syntax.
5 * Base language object with methods related to language support, attempting to mirror some of the
6 * functionality of the Language class in MediaWiki:
8 * - storing and retrieving language data
9 * - transforming message syntax (`{{PLURAL:}}`, `{{GRAMMAR:}}`,
10 * `{{GENDER:}}`, `{{#FORMAL:}}`)
11 * - formatting numbers
13 * @namespace mw.language
18 * Language-related data (keyed by language, contains instances of mw.Map).
20 * Exported dynamically by the ResourceLoader\LanguageDataModule class in PHP.
24 * // Override, extend or create the language data object of 'nl'
25 * mw.language.setData( 'nl', 'myKey', 'My value' );
27 * // Set multiple key/values pairs at once
28 * mw.language.setData( 'nl', { foo: 'X', bar: 'Y' } );
31 * To get GrammarForms data for language 'nl':
33 * var grammarForms = mw.language.getData( 'nl', 'grammarForms' );
38 * - `digitTransformTable`
39 * - `separatorTransformTable`
40 * - `minimumGroupingDigits`
44 * - `digitGroupingPattern`
45 * - `fallbackLanguages`
54 * Convenience method for retrieving language data.
56 * Structured by language code and data key, covering for the potential inexistence of a
57 * data object for this language.
59 * @param {string} langCode
60 * @param {string} dataKey
61 * @return {any} Value stored in the mw.Map (or `undefined` if there is no map for the
64 getData: function ( langCode, dataKey ) {
65 const langData = mw.language.data;
66 langCode = langCode.toLowerCase();
67 if ( langData && langData[ langCode ] instanceof mw.Map ) {
68 return langData[ langCode ].get( dataKey );
74 * Convenience method for setting language data.
76 * Creates the data {@link mw.Map} if there isn't one for the specified language already.
78 * @param {string} langCode
79 * @param {string|Object} dataKey Key or object of key/values
80 * @param {any} [value] Value for dataKey, omit if dataKey is an object
82 setData: function ( langCode, dataKey, value ) {
83 const langData = mw.language.data;
84 langCode = langCode.toLowerCase();
85 if ( !( langData[ langCode ] instanceof mw.Map ) ) {
86 langData[ langCode ] = new mw.Map();
88 if ( arguments.length > 2 ) {
89 langData[ langCode ].set( dataKey, value );
91 langData[ langCode ].set( dataKey );