Module: Core/Language

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
key string

Key of the string to retrieve.

module string | 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.

context string | 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 key parameter 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
listName string

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
key string

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
key string

Key of the string to retrieve.

context string | 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. undefined if 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
key string

Key of the string to retrieve.

module string | 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.

context string | 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. undefined if 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 module passed in.

Parameters:
Name Type Argument Description
module string

The module.

options Object <optional>

Options object for getModuleName.

Properties
Name Type Argument Description
plural boolean <optional>

Returns the plural form if true, singular otherwise.

defaultValue string <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
language string

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
language string

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
lang string

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
language string

language code such as en_us.

callback function <optional>

Callback function to be called on language set completes.

options Object <optional>

Extra options.

Properties
Name Type Argument Default Description
noSync boolean <optional>
false

true if you don't need to fetch /metadata.

noUserUpdate boolean <optional>
false

true if you don't need to update /me.


<static> updateLanguage(language)

Updates language code and the display direction.

Parameters:
Name Type Description
language string

Language code as defined in Sugar. (e.g. en_us, pt_PT)