[ Index ] |
PHP Cross Reference of MediaWiki-1.24.0 |
[Summary view] [Print] [Text view]
1 ( function ( mw ) { 2 /** 3 * Base language object with methods related to language support, attempting to mirror some of the 4 * functionality of the Language class in MediaWiki: 5 * 6 * - storing and retrieving language data 7 * - transforming message syntax (`{{PLURAL:}}`, `{{GRAMMAR:}}`, `{{GENDER:}}`) 8 * - formatting numbers 9 * 10 * @class 11 * @singleton 12 */ 13 mw.language = { 14 /** 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). 18 * 19 * To set data: 20 * 21 * // Override, extend or create the language data object of 'nl' 22 * mw.language.setData( 'nl', 'myKey', 'My value' ); 23 * 24 * // Set multiple key/values pairs at once 25 * mw.language.setData( 'nl', { foo: 'X', bar: 'Y' } ); 26 * 27 * To get GrammarForms data for language 'nl': 28 * 29 * var grammarForms = mw.language.getData( 'nl', 'grammarForms' ); 30 * 31 * Possible data keys: 32 * 33 * - `digitTransformTable` 34 * - `separatorTransformTable` 35 * - `grammarForms` 36 * - `pluralRules` 37 * - `digitGroupingPattern` 38 * - `fallbackLanguages` 39 * 40 * @property 41 */ 42 data: {}, 43 44 /** 45 * Convenience method for retrieving language data. 46 * 47 * Structured by language code and data key, covering for the potential inexistence of a 48 * data object for this language. 49 * 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 53 * specified langCode) 54 */ 55 getData: function ( langCode, dataKey ) { 56 var langData = mw.language.data; 57 if ( langData && langData[langCode] instanceof mw.Map ) { 58 return langData[langCode].get( dataKey ); 59 } 60 return undefined; 61 }, 62 63 /** 64 * Convenience method for setting language data. 65 * 66 * Creates the data mw.Map if there isn't one for the specified language already. 67 * 68 * @param {string} langCode 69 * @param {string|Object} dataKey Key or object of key/values 70 * @param {Mixed} [value] Value for dataKey, omit if dataKey is an object 71 */ 72 setData: function ( langCode, dataKey, value ) { 73 var langData = mw.language.data; 74 if ( !( langData[langCode] instanceof mw.Map ) ) { 75 langData[langCode] = new mw.Map(); 76 } 77 langData[langCode].set( dataKey, value ); 78 } 79 }; 80 81 }( mediaWiki ) );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 14:03:12 2014 | Cross-referenced by PHPXref 0.7.1 |