2 * Base language object with methods for storing and getting
9 * @var data {Object} Language related data (keyed by language,
10 * contains instances of mw.Map).
13 * // Override, extend or create the language data object of 'nl'
14 * mw.language.setData( 'nl', 'myKey', 'My value' );
16 * // Set multiple values at once
17 * mw.language.setData( 'nl', { 'foo': 'X', 'bar': 'Y' } );
19 * @example Get GrammarForms data for language 'nl':
21 * var grammarForms = mw.language.getData( 'nl', 'grammarForms' );
27 * Convenience method for retreiving language data by language code and data key,
28 * covering for the potential inexistance of a data object for this langiage.
29 * @param langCode {String}
30 * @param dataKey {String}
31 * @return {mixed} Value stored in the mw.Map (or undefined if there is no map for
32 the specified langCode).
34 getData: function ( langCode, dataKey ) {
35 var langData = language.data;
36 if ( langData && langData[langCode] instanceof mw.Map ) {
37 return langData[langCode].get( dataKey );
43 * Convenience method for setting language data by language code and data key.
44 * Creates the data mw.Map if there isn't one for the specified language already.
46 * @param langCode {String}
47 * @param dataKey {String|Object} Key or object of key/values.
48 * @param value {mixed} Value for dataKey, ignored if dataKey is an object.
50 setData: function ( langCode, dataKey, value ) {
51 var langData = language.data;
52 if ( !( langData[langCode] instanceof mw.Map ) ) {
53 langData[langCode] = new mw.Map();
55 langData[langCode].set( dataKey, value );
59 mw.language = language;