_mod
private
Object
_mod
(
module
)
Private method to retrieve the language hash for a given module.
- Parameters:
-
module <String>
The name of the module
- Returns:
Object
- The hash of localized resources for the module, keyed by BCP language tag
add
void
add
(
module
,
lang
,
strings
)
Register a hash of localized resources for the given module and language
- Parameters:
-
module <String>
The module name. -
lang <String>
The BCP 47 language tag. -
strings <Object>
The hash of localized values, keyed by the string name.
get
get
(
module
,
key
,
lang
)
Gets the module's localized resources for the currently active language (as provided by the getLang method).
Optionally, the localized resources for alternate languages which have been added to Intl (see the add method) can be retrieved by providing the BCP 47 language tag as the lang parameter.
- Parameters:
-
module <String>
The module name. -
key <String>
Optional. A single resource key. If not provided, returns a copy (shallow clone) of all resources. -
lang <String>
Optional. The BCP 47 language tag. If not provided, the module's currently active language is used.
- Returns:
- String | Object A copy of the module's localized resources, or a single value if key is provided.
getAvailableLangs
Array
getAvailableLangs
(
module
)
Gets the list of languages for which localized resources are available for a given module, based on the module
meta-data (part of loader). If loader is not on the page, returns an empty array.
- Parameters:
-
module <String>
The name of the module
- Returns:
Array
- The array of languages available.
getLang
String
getLang
(
module
)
Get the currently active language for the given module.
- Parameters:
-
module <String>
The module name.
- Returns:
String
- The BCP 47 language tag.
lookupBestLang
String
lookupBestLang
(
preferredLanguages
,
availableLanguages
)
Returns the language among those available that
best matches the preferred language list, using the Lookup
algorithm of BCP 47.
If none of the available languages meets the user's preferences,
then "" is returned.
Extended language ranges are not supported.
- Parameters:
-
preferredLanguages <String[] | String>
The list of preferred languages in descending preference order, represented as BCP 47 language tags. A string array or a comma-separated list. -
availableLanguages <String[]>
The list of languages that the application supports, represented as BCP 47 language tags.
- Returns:
String
- The available language that best matches the preferred language list, or "".
setLang
setLang
(
module
,
lang
)
Sets the active language for the given module.
Returns false on failure, which would happen if the language had not been registered through the add() method.
- Parameters:
-
module <String>
The module name. -
lang <String>
The BCP 47 language tag.
- Returns:
- boolean true if successful, false if not.