Class ilib.Locale
Create a new locale instance. Locales are specified either with a specifier string that follows the BCP-47 convention (roughly: "language-region-script-variant") or with 4 parameters that specify the language, region, variant, and script individually.
The language is given as an ISO 639-1 two-letter, lower-case language code. You can find a full list of these codes at http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
The region is given as an ISO 3166-1 two-letter, upper-case region code. You can find a full list of these codes at http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2.
The variant is any string that does not contain a dash which further differentiates locales from each other.
The script is given as the ISO 15924 four-letter script code. In some locales, text may be validly written in more than one script. For example, Serbian is often written in both Latin and Cyrillic, though not usually mixed together. You can find a full list of these codes at http://en.wikipedia.org/wiki/ISO_15924#List_of_codes.
As an example in ilib, the script can be used in the date formatter. Dates formatted in Serbian could have day-of-week names or month names written in the Latin or Cyrillic script. Often one script is default such that sr-SR-Latn is the same as sr-SR so the script code "Latn" can be left off of the locale spec.
Each part is optional, and an empty string in the specifier before or after a dash or as a parameter to the constructor denotes an unspecified value. In this case, many of the ilib functions will treat the locale as generic. For example the locale "en-" is equivalent to "en" and to "en--" and denotes a locale of "English" with an unspecified region and variant, which typically matches any region or variant.
Without any arguments to the constructor, this function returns the locale of the host Javascript engine.
Depends directive: !depends locale.js
Defined in: ilib-dyn-full.js.
Constructor Attributes | Constructor Name and Description |
---|---|
ilib.Locale(language, region, variant, script)
|
Method Attributes | Method Name and Description |
---|---|
equals(other)
Return true if the the other locale is exactly equal to the current one.
|
|
<static> |
ilib.Locale.getAvailableLocales()
Return the list of available locales that this iLib file was assembled
with.
|
Return the ISO 639 language code for this locale.
|
|
Return the language of this locale as an ISO-639-alpha3 language code
|
|
Return the ISO 3166 region code for this locale.
|
|
Return the region of this locale as an ISO-3166-alpha3 region code
|
|
Return the ISO 15924 script code for this locale
|
|
getSpec()
Return the whole locale specifier as a string.
|
|
Return the variant code for this locale
|
|
isPseudo()
Return true if the current locale is the special pseudo locale.
|
|
<static> |
ilib.Locale.languageAlpha1ToAlpha3(alpha1)
Return the ISO-639 alpha3 equivalent language code for the given ISO 639 alpha1
language code.
|
<static> |
ilib.Locale.regionAlpha2ToAlpha3(alpha2)
Return the ISO-3166 alpha3 equivalent region code for the given ISO 3166 alpha2
region code.
|
toString()
Express this locale object as a string.
|
- Parameters:
- {?string|ilib.Locale=} language
- the ISO 639 2-letter code for the language, or a full locale spec in BCP-47 format, or another ilib.Locale instance to copy from
- {string=} region
- the ISO 3166 2-letter code for the region
- {string=} variant
- the name of the variant of this locale, if any
- {string=} script
- the ISO 15924 code of the script for this locale, if any
- Parameters:
- other
- Returns:
- {boolean} whether or not the other locale is equal to the current one
- Returns:
- {Array.<string>} this is an array of locale specs for which this iLib file has locale data for
- Returns:
- {string|undefined} the language code for this locale
- Returns:
- {string|undefined} the alpha3 language code of this locale
- Returns:
- {string|undefined} the region code of this locale
- Returns:
- {string|undefined} the alpha3 region code of this locale
- Returns:
- {string|undefined} the script code of this locale
- Returns:
- {string} the locale specifier
- Returns:
- {string|undefined} the variant code of this locale, if any
- Returns:
- {boolean} true if the current locale is the special pseudo locale
- Parameters:
- {string|undefined} alpha1
- the alpha1 code to map
- Returns:
- {string|undefined} the alpha3 equivalent of the given alpha1 code, or the alpha1 parameter if the alpha1 value is not found
- Parameters:
- {string|undefined} alpha2
- the alpha2 code to map
- Returns:
- {string|undefined} the alpha3 equivalent of the given alpha2 code, or the alpha2 parameter if the alpha2 value is not found
- Returns:
- {string} the locale specifier