Expand all

mw.language

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:

Source:
Language-related data (keyed by language, contains instances of mw.Map).

months :Monthsstatic #

Information about month names in current UI language.

Type:

Source:
Information about month names in current UI language.

Methods

bcp47(languageTag) → {string}static #

Formats language tags according the BCP 47 standard. See LanguageCode::bcp47 for the PHP implementation.

Parameters:

Name Type Description
languageTag string

Well-formed language tag

Source:

Returns:

Type
string
Formats language tags according the BCP 47 standard.

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:

Name Type Description
word string
form string
Source:

Returns:

Type
string
Grammatical transformations, needed for inflected languages.

convertNumber(num, [integer]) → {number|string}static #

Converts a number using getDigitTransformTable().

Parameters:

Name Type Attributes Default Description
num number

Value to be converted

integer boolean optional
false

Whether to convert the return value to an integer

Source:

Returns:

Formatted number

Type
number | string
Converts a number using 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

Source:

Returns:

Correct form for quantifier in this language

Type
string
Plural form transformations, needed for some languages.

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

Source:

Returns:

Type
string
Provides an alternative text depending on specified gender.

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:

Name Type Description
langCode string
dataKey string
Source:

Returns:

Value stored in the mw.Map (or undefined if there is no map for the specified langCode)

Type
any
Convenience method for retrieving language data.

getFallbackLanguageChain() → {Array.<string>}static #

Get the language fallback chain for current UI language, including the language itself.

Source:

Returns:

List of language keys, e.g. ['pfl', de', 'en']

Type
Array.<string>
Get the language fallback chain for current UI language, including the language itself.

getFallbackLanguages() → {Array.<string>}static #

Get the language fallback chain for current UI language (not including the language itself).

Source:

Returns:

List of language keys, e.g. ['de', 'en']

Type
Array.<string>
Get the language fallback chain for current UI language (not including the language itself).

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:

Name Type Description
list Array.<string>
Source:

Returns:

Type
string
Turn a list of string into a simple list using commas and 'and'.

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:

Name Type Attributes Description
langCode string
dataKey string | Object

Key or object of key/values

value any optional

Value for dataKey, omit if dataKey is an object

Source:
Convenience method for setting language data.

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

Source: