Localization Class
Provides functions to translate items based on keys. Also assists in the determination of the best language for the given user.
Item Index
Methods
- _registerLocale static
- _registerLocale static
- _registerLocalization static
- _registerLocalization static
- assertOptions static
- best
- containsParameters static
- findKeyBlock static
- formatLocale static
- g
- get deprecated
- getDefaultLocale static
- getLocalizationPackage static
- getSupported static
- getSupportedWithDisplay static
- init
- isSupported static
- k static
- localize deprecated
- parseLocale static
- parseLocaleStr static
- registerLocalizations static deprecated
- replaceParameters static
- unregisterLocale static
- unregisterLocalization static
Properties
- ACCEPT_LANG_HEADER static
- activeTheme
- cache
- JS_EXT
- KEY_SEP static
- language Really should be renamed to locale in the future
- LOCALE_PART_SEP static
- localeObj
- PARAM_REPLACEMENT_REGEX static
- PREFIX static
- SEP static
- storage static
- supported static
- supportedLookup static
Methods
_registerLocale
-
locale
-
localizations
-
[options]
Registers a localization package for the provided locale. Optionally, the packaged can be scoped to a specific plugin.
Parameters:
-
locale
String | Object-
[language]
String optionalOnly required when passing locale as an object
-
[countryCode]
String optional
-
-
localizations
Object -
[options]
Object optional-
[plugin=SYSTEM]
String optional
-
Returns:
_registerLocale
-
locale
-
localizations
-
[options]
Registers a localization package for the provided locale and plugin.
Parameters:
-
locale
String | Object -
localizations
Object -
[options]
Object optional-
[plugin]
String optional
-
Returns:
_registerLocalization
-
locale
-
key
-
value
-
options
Registers a single localization key for the provided locale and plugin.
Parameters:
-
locale
String -
key
String -
value
String -
options
Object-
plugin
String
-
Returns:
_registerLocalization
-
locale
-
key
-
value
-
[options]
Registers a single localization key for the provided locale. Optionally, the localization can be scoped to a single plugin.
Parameters:
-
locale
String | Object-
[language]
String optionalOnly required when passing locale as an object
-
[countryCode]
String optional
-
-
key
String -
value
String -
[options]
Object optional-
[plugin]
String optional
-
Returns:
assertOptions
-
options
Asserts that the options parameter is provided and that it contains a property "plugin" that is a string.
Parameters:
-
options
Object-
plugin
String
-
best
-
request
-
[supported]
Determines the best language to send a user based on the 'accept-language' header in the request
Parameters:
-
request
Request | StringThe request object
-
[supported]
Array optionalThe array of supported locales
Returns:
Locale for the request
containsParameters
-
localizationValue
Determines if a raw localization value contains named parameters
Parameters:
-
localizationValue
String
Returns:
findKeyBlock
-
key
-
create
Navigates the storage structure to find where a localization key's values live
Parameters:
-
key
String -
create
Boolean
Returns:
The object that contains the values for the key
formatLocale
-
language
-
[countryCode]
Formats a language and an optional country code into a proper locale format (lang-COUNTRY)
Parameters:
-
language
String -
[countryCode]
String optional
Returns:
g
-
key
-
[options]
Parameters:
-
key
String -
[options]
Object optional-
[site=global]
String optional -
[params={}]
Object optional -
[plugin]
Object optional
-
Returns:
get
-
key
-
[args]
Translates a single key. The function accepts a variable number of parameters. The first must be the key to be localized. The rest are considered to be injectable values. The function will call "util.format" in situations where the key is found and the nuber of arguments passed to the function is greater than 1. See http://nodejs.org/api/util.html#util_util_format_format for details on supported formatting.
Parameters:
-
key
String -
[args]
String | Integer | Number | Object optionalThe variable number of parameters to be injected into the localization value
Returns:
The formatted and localized string
getDefaultLocale
()
String
static
Retrieves the default locale for the instance. It first inspects the Configuration property localization.defaultLocale. As a last resort it will fall back to english. The locale is expected to be of the form: [language code]_[country code]
Returns:
The default locale
getLocalizationPackage
-
locale
-
[options]
Retrieves the localization package for the specified locale
Parameters:
-
locale
String -
[options]
Object optionalSee options for Localization.g
Returns:
getSupported
()
Array
static
Retrieves the supported locales
Returns:
getSupportedWithDisplay
()
Array
static
Retrieves the supported locales as an array where each item in the array contains a value (locale) and a name (locale specific representation of the locale).
Returns:
init
-
cb
Initializes the location. Loads all language packs into memory for fast retrieval and sets the supported locales for determining what language to send the user based on their list of acceptable languages.
Parameters:
-
cb
Function
isSupported
-
locale
Determines if there have been keys registered for the specified locale. An example locale string would be: en-US. Where the characters to the left of the dash are the language code and the characters to the right of the dash represent the country code.
Parameters:
-
locale
String
Returns:
k
-
key
Formats a given key to be formatted as a "private" property in the storage structure. This is to prevent collisions between localization keys.
Parameters:
-
key
String
Returns:
localize
-
sets
-
text
-
hostname
Localizes a string by searching for keys within the template and replacing them with the specified values.
Parameters:
-
sets
ArrayThe localizations sets to search in
-
text
StringThe text to localize
-
hostname
StringThe current hostname
Returns:
The text where keys have been replaced with translated values
parseLocale
-
locale
Takes a locale object or string representation. When a string it is parsed to an object. When an object is passed it is verified. The function throws an error when it finds invalid format.
Parameters:
-
locale
String | Object-
[language]
String optionalOnly required when passing an object
-
Returns:
parseLocaleStr
-
filePath
Parses a locale or file path to a locale file and extracts the language and country code into an object.
Parameters:
-
filePath
String | Object-
[language]
String optionalOnly required when passing filePath as an object
-
[countryCode]
String optionalOnly required when passing filePath as an object
-
Returns:
registerLocalizations
-
locale
-
localizations
-
options
Parameters:
-
locale
String -
localizations
Object -
options
Object-
[plugin]
String optional
-
Returns:
replaceParameters
-
value
-
params
-
[defaultVal]
Given a raw localization value and a set of parameters the function will attempt to replace the named parameters in the raw value with the values provided in the params. When a named parameter is found that was not provided a value the defaultVal parameter value is used.
Parameters:
-
value
String -
params
Object -
[defaultVal]
String optional
Returns:
unregisterLocale
-
locale
-
[options]
Removes a locale and all keys associated with it. Optionally, the operation can be scoped to a single plugin.
Parameters:
-
locale
String | Object-
[language]
String optionalOnly required when locale is passed as an object
-
[countryCode]
String optional
-
-
[options]
Object optional-
[plugin]
String optional
-
Returns:
unregisterLocalization
-
locale
-
key
-
[options]
Unregisters a single key for the given locale. The locale can be just the language or the combination of the language and country code. Additionally, the operation can be scoped to a single plugin.
Parameters:
-
locale
String | Object-
[language]
String optionalOnly required when passing locale as an object
-
[countryCode]
String optional
-
-
key
String -
[options]
Object optional-
[plugin]
String optional
-
Returns:
Properties
ACCEPT_LANG_HEADER
String
static
activeTheme
String
The currently active theme that should be prioritized when performing key lookup
cache
Object
Stores the keys already retrieved for the instance to prevent duplicate retrieval.
JS_EXT
String
KEY_SEP
String
static
language Really should be renamed to locale in the future
String
expected to be lowercase and of the form "en-us"