Methods for transforming message syntax.
Base language object with methods related to language support, attempting to mirror some of the functionality of the Language class in MediaWiki:
- storing and retrieving language data
- transforming message syntax (
{{PLURAL:}}
,{{GRAMMAR:}}
,{{GENDER:}}
,{{#FORMAL:}}
) - formatting numbers
Properties
data :Objectstatic
#
Language-related data (keyed by language, contains instances of mw.Map).
Exported dynamically by the ResourceLoader\LanguageDataModule class in PHP.
To set data:
// Override, extend or create the language data object of 'nl'
mw.language.setData( 'nl', 'myKey', 'My value' );
// Set multiple key/values pairs at once
mw.language.setData( 'nl', { foo: 'X', bar: 'Y' } );
To get GrammarForms data for language 'nl':
var grammarForms = mw.language.getData( 'nl', 'grammarForms' );
Possible data keys:
digitTransformTable
separatorTransformTable
minimumGroupingDigits
formalityIndex
grammarForms
pluralRules
digitGroupingPattern
fallbackLanguages
bcp47Map
languageNames
Type:
Methods
bcp47(languageTag) → {string}static
#
convertGrammar(word, form) → {string}static
#
Grammatical transformations, needed for inflected languages.
Invoked by putting {{grammar:case|word}}
in a message.
The rules can be defined in $wgGrammarForms global or computed dynamically by overriding this method per language.
Parameters:
Returns:
- Type
- string
convertNumber(num, [integer]) → {number|string}static
#
getDigitTransformTable()
.
convertPlural(count, forms, [explicitPluralForms]) → {string}static
#
Plural form transformations, needed for some languages.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
count |
number | Non-localized quantifier |
|
forms |
Array | List of plural forms |
|
explicitPluralForms |
Object |
optional |
List of explicit plural forms |
Returns:
Correct form for quantifier in this language
- Type
- string
gender(gender, forms) → {string}static
#
Provides an alternative text depending on specified gender.
Usage in message text: {{gender:[gender|user object]|masculine|feminine|neutral}}
.
If second or third parameter are not specified, masculine is used.
These details may be overridden per language.
Parameters:
Name | Type | Description |
---|---|---|
gender |
string | 'male', 'female', or anything else for neutral. |
forms |
Array | List of gender forms |
Returns:
- Type
- string
getData(langCode, dataKey) → {any}static
#
Convenience method for retrieving language data.
Structured by language code and data key, covering for the potential inexistence of a data object for this language.
Parameters:
Returns:
Value stored in the mw.Map (or undefined
if there is no map for the
specified langCode)
- Type
- any
getFallbackLanguageChain() → {Array.<string>}static
#
Get the language fallback chain for current UI language, including the language itself.
Returns:
List of language keys, e.g. ['pfl', de', 'en']
getFallbackLanguages() → {Array.<string>}static
#
Get the language fallback chain for current UI language (not including the language itself).
Returns:
List of language keys, e.g. ['de', 'en']
listToText(list) → {string}static
#
Turn a list of string into a simple list using commas and 'and'.
See Language::listToText in languages/Language.php
Parameters:
Returns:
- Type
- string
setData(langCode, dataKey, [value])static
#
Convenience method for setting language data.
Creates the data mw.Map
if there isn't one for the specified language already.
Parameters:
Type Definitions
Months
#
Type:
Properties:
Name | Type | Description |
---|---|---|
names |
Array | Month names (in nominative case in languages which have the distinction), zero-indexed |
genitive |
Array | Month names in genitive case, zero-indexed |
abbrev |
Array | Three-letter-long abbreviated month names, zero-indexed |
key |
Object | Object with three keys like the above, containing zero-indexed arrays of message keys for appropriate messages which can be passed to mw.msg |