Language Helper.
Provides convenient functions to pull language strings out of a language label cache.
Members
-
<static> direction :string
-
The display direction for the current language.
Type:
- string
Methods
-
<static> get(key [, module] [, context])
-
Retrieves a string for a given key.
This function searches the module strings first and falls back to the app strings.
If the label is a template, it will be compiled and executed with the given
context.Parameters:
Name Type Argument Description keystring Key of the string to retrieve.
modulestring | Array <optional>
Module the label belongs to. If an array is passed, it will look through each module by the given order, returning the first string whose key is found in the module's language strings.
contextstring | boolean | number | Array | Object <optional>
The template context to pass to the template in order to populate template variables.
Returns:
String for the given key or the
keyparameter if the key is not found in language pack.- Type
- string
-
<static> getAppListKeys(listName)
-
Returns the correct ordered array of strings for a given list.
Parameters:
Name Type Description listNamestring Name of the strings array to retrieve.
Returns:
The array of strings.
- Type
- Array
-
<static> getAppListStrings(key)
-
Retrieves an application list string or object.
Parameters:
Name Type Description keystring Key of the string to retrieve.
Returns:
String or object for the given key. If key is not found, an empty object is returned.
- Type
- string | Object
-
<static> getAppString(key [, context])
-
Retrieves an application string for a given key.
Parameters:
Name Type Argument Description keystring Key of the string to retrieve.
contextstring | boolean | number | Array | Object <optional>
The template context to pass to the string/template in order to populate template variables.
Returns:
String for the given key from language strings.
undefinedif not found.- Type
- string | undefined
-
<static> getDefaultLanguage()
-
Gets the default language set in the system.
Returns:
The IETF's BCP 47 language code of the default language. (e.g.
en_us,pt_PT). Note: We use_instead of-.- Type
- string
-
<static> getLanguage()
-
Gets the IETF's BCP 47 language code for the current app language.
Returns:
The IETF's BCP 47 language code of the default language. (e.g.
en_us,pt_PT). Note: We use_instead of-.- Type
- string
-
<static> getModString(key [, module] [, context])
-
Searches the module strings for a given key.
Parameters:
Name Type Argument Description keystring Key of the string to retrieve.
modulestring | Array <optional>
Module the label belongs to. If an array is passed, it will look through each module by the given order, returning the first string whose key is found in the module's language strings.
contextstring | boolean | number | Array | Object <optional>
The template context to pass to the template in order to populate template variables.
Returns:
String for the given key from the module language strings.
undefinedif not found.- Type
- string | undefined
-
<static> getModuleName(module [, options])
-
Gets the translated module name (by default, in singular form).
Falls back to the plural form if the singular form is not found, and eventually falls back to the
modulepassed in.Parameters:
Name Type Argument Description modulestring The module.
optionsObject <optional>
Options object for
getModuleName.Properties
Name Type Argument Description pluralboolean <optional>
Returns the plural form if
true, singular otherwise.defaultValuestring <optional>
Value to be returned if the module language string is not found.
Returns:
The module name.
- Type
- string
-
<static> setCurrentLanguage(language)
-
Sets the current language to the language specified. Use #getLanguage to get the current language.
Calls #setDirection with the new language code.
Parameters:
Name Type Description languagestring The language to set the current language to.
-
<static> setDefaultLanguage(language)
-
Sets the app default language to the language specified. Use #getDefaultLanguage to get the current language.
Parameters:
Name Type Description languagestring The IETF's BCP 47 language code to set the default language to. (e.g.
en_us,pt_PT). Note: We use_instead of-. -
<static> setDirection(lang)
-
Sets the #direction to the desired direction according to the language code specified.
Parameters:
Name Type Description langstring Language code that the direction is based on.
Fires:
- 'lang:direction:change' if the language direction has changed.event:
-
<static> setLanguage(language [, callback] [, options])
-
Sets app language code and syncs it with the server.
Parameters:
Name Type Argument Description languagestring language code such as
en_us.callbackfunction <optional>
Callback function to be called on language set completes.
optionsObject <optional>
Extra options.
Properties
Name Type Argument Default Description noSyncboolean <optional>
false trueif you don't need to fetch /metadata.noUserUpdateboolean <optional>
false trueif you don't need to update /me. -
<static> updateLanguage(language)
-
Updates language code and the display direction.
Parameters:
Name Type Description languagestring Language code as defined in Sugar. (e.g.
en_us,pt_PT)