Class Index | File Index

Classes


Class 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.


Defined in: ilib-full-dyn.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
Locale(language, region, variant, script)
Method Summary
Method Attributes Method Name and Description
 
equals(other)
Return true if the the other locale is exactly equal to the current one.
<static>  
Locale.getAvailableLocales(sync, onLoad)
Return the list of available locales that this iLib file supports.
 
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
 
Return the whole locale specifier as a string.
 
Return the variant code for this locale
 
Return true if the current locale is the special pseudo locale.
<static>  
Locale.languageAlpha1ToAlpha3(alpha1)
Return the ISO-639 alpha3 equivalent language code for the given ISO 639 alpha1 language code.
<static>  
Locale.regionAlpha2ToAlpha3(alpha2)
Return the ISO-3166 alpha3 equivalent region code for the given ISO 3166 alpha2 region code.
 
Express this locale object as a string.
Class Detail
Locale(language, region, variant, script)
Parameters:
{?string|Locale=} language
the ISO 639 2-letter code for the language, or a full locale spec in BCP-47 format, or another 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
Method Detail
{boolean} equals(other)
Return true if the the other locale is exactly equal to the current one.
Parameters:
other
Returns:
{boolean} whether or not the other locale is equal to the current one

<static> {Array.<string>} Locale.getAvailableLocales(sync, onLoad)
Return the list of available locales that this iLib file supports. If this copy of ilib is pre-assembled with locale data, then the list locales may be much smaller than the list of all available locales in the iLib repository. The assembly tool will automatically fill in the list for an assembled copy of iLib. If this copy is being used with dynamically loaded data, then you can load any locale that iLib supports. You can form a locale with any combination of a language and region tags that exist in the locale data directory. Language tags are in the root of the locale data dir, and region tags can be found underneath the "und" directory. (The region tags are separated into a different dir because the region names conflict with language names on file systems that are case-insensitive.) If you have culled the locale data directory to limit the size of your app, then this function should return only those files that actually exist according to the ilibmanifest.json file in the root of that locale data dir. Make sure your ilibmanifest.json file is up-to-date with respect to the list of files that exist in the locale data dir.
Parameters:
{boolean} sync
if false, load the list of available files from disk asynchronously, otherwise load them synchronously. (Default: true/synchronously)
{Function} onLoad
a callback function to call if asynchronous load was requested and the list of files have been loaded.
Returns:
{Array.<string>} this is an array of locale specs for which this iLib file has locale data for

{string|undefined} getLanguage()
Return the ISO 639 language code for this locale.
Returns:
{string|undefined} the language code for this locale

{string|undefined} getLanguageAlpha3()
Return the language of this locale as an ISO-639-alpha3 language code
Returns:
{string|undefined} the alpha3 language code of this locale

{string|undefined} getRegion()
Return the ISO 3166 region code for this locale.
Returns:
{string|undefined} the region code of this locale

{string|undefined} getRegionAlpha3()
Return the region of this locale as an ISO-3166-alpha3 region code
Returns:
{string|undefined} the alpha3 region code of this locale

{string|undefined} getScript()
Return the ISO 15924 script code for this locale
Returns:
{string|undefined} the script code of this locale

{string} getSpec()
Return the whole locale specifier as a string.
Returns:
{string} the locale specifier

{string|undefined} getVariant()
Return the variant code for this locale
Returns:
{string|undefined} the variant code of this locale, if any

{boolean} isPseudo()
Return true if the current locale is the special pseudo locale.
Returns:
{boolean} true if the current locale is the special pseudo locale

<static> {string|undefined} Locale.languageAlpha1ToAlpha3(alpha1)
Return the ISO-639 alpha3 equivalent language code for the given ISO 639 alpha1 language code. If the given alpha1 code is not found, this function returns its argument unchanged.
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

<static> {string|undefined} Locale.regionAlpha2ToAlpha3(alpha2)
Return the ISO-3166 alpha3 equivalent region code for the given ISO 3166 alpha2 region code. If the given alpha2 code is not found, this function returns its argument unchanged.
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

{string} toString()
Express this locale object as a string. Currently, this simply calls the getSpec function to represent the locale as its specifier.
Returns:
{string} the locale specifier

Documentation generated by JsDoc Toolkit 2.4.0 on Tue Feb 02 2016 15:53:55 GMT-0800 (PST)