App.i18n

The App.i18n is responsible for all client side internationalisation.

Members

(static) window.App.i18n

Methods

(static) exists(key) → {boolean}

Checks if a translation key exists

Parameters:
Name Type Description
key String

The key to check for existence

Returns:

True if the key is found, otherwise false

Type
boolean

(static) t(key, args) → {String}

Translates the given key to a string using the optional arguments necessary for resolving the string.

Examples
// Simple translation
var translation = App.i18n.t('myapp.key');
// Using substitution
// myapp.another.key has the value 'Hello {name}! You are {age}.'
var data = {'name': 'Kalle', 'age': 75};
var translation = App.i18n.t('myapp.another.key', data);
Parameters:
Name Type Description
key String

Key to translate

args Object

Optional: Arguments used to substitute values in the string

Returns:

The translated string

Type
String

(static) translateIfExists(key, args) → {String}

Translate key if it exists otherwise returns the passed in key

Parameters:
Name Type Description
key String

The key to translate

args Object

Optional: Arguments used to substitute values in the string

Returns:

translation Returns the translation

Type
String

(static) translationSubnode(path,) → {Object}

Fetches a subnode of the translation tree with the given path. If nothing is found an empty object will be returned and if the path points to a leaf in the tree the value for that key will be returned.

Example
// Given the following translation tree, and a user with the browser locale set to en-US.
// default.json
// {
//  form: {
//     messages: {
//        tooShort: "The value is too short",
//        tooLong: "The value is too long"
//     }
//  }
//}
// en_us.json
// {
//   form: {
//     messages: {
//        tooShort: "The value is way to short!"
//     }
//   }
// }
// The call below
App.i18n.translationSubnode('form.messages')
// would return
// {
//  tooShort: "The value is way to short!",
//  tooLong: "The value is too long"
// }
Parameters:
Name Type Description
path, String

Path to the subnode in the translation tree

Returns:

, Object at the given path, if nothing is found an empty object will be returned

Type
Object