Class Granite.I18n
| Package: | Granite |
| Class: | I18n |
| Extends: | Object |
| Clientlib: | <unknown> , * |
A helper class providing a set of utilities related to internationalization (i18n).
Locale Priorities
The locale is read based on the following priorities:
- manually specified locale
document.documentElement.lang
Granite.I18n.LOCALE_DEFAULT
Dictionary Priorities
The dictionary URL is read based on the following priorities:
- manually specified URL (
urlPrefixurlSuffix)
data-i18n-dictionary-src attribute at <html> element, which has the type of URI Template string
- The URL resolved from default
urlPrefix and urlSuffix
URI Template of data-i18n-dictionary-src
It expects the variable named locale, which will be fetched from the locale (based on priorities above).
E.g. <html lang="en" data-i18n-dictionary-src="/libs/cq/i18n/dict.{+locale}.json">.
This class is a singleton and cannot be created directly.
Public Properties
| |
I18n.LOCALE_DEFAULT : String
<static> The default locale (en).
|
I18n |
| |
I18n.PSEUDO_LANGUAGE : String
<static> Language code for pseudo translations.
|
I18n |
| |
I18n.PSEUDO_PATTERN_KEY : String
<static> Dictionary key for pseudo translation pattern.
|
I18n |
Public Methods
| |
I18n.get( String text, [String[] snippets], [String note] ) : String
<static> Translates the specified text into the current language.
<static> Translates the specified text into the current language.
Parameters:
Returns:
StringThe translated text
|
I18n |
| |
I18n.getDictionary( [String locale] ) : Object
<static> Returns the dictionary for the specified locale. This method
will request the dictionary using the URL...
<static> Returns the dictionary for the specified locale. This method
will request the dictionary using the URL prefix, the locale,
and the URL suffix. If no locale is specified, the current
locale is used.
Parameters:
locale : String(optional) The locale
Returns:
|
I18n |
| |
I18n.getLanguages() : Object
<static> Returns the available languages, including a "title" property with a display name:
for instance "Germa...
<static> Returns the available languages, including a "title" property with a display name:
for instance "German" for "de" or "German (Switzerland)" for "de_ch".
|
I18n |
| |
I18n.getLocale() : String
<static> Returns the current locale based on the priorities.
<static> Returns the current locale based on the priorities.
|
I18n |
| |
I18n.getVar( String text, [String note] ) : String
<static> Translates the specified text into the current language. Use this
method to translate String variables...
<static> Translates the specified text into the current language. Use this
method to translate String variables, e.g. data from the server.
Parameters:
Returns:
StringThe translated text
|
I18n |
| |
I18n.parseLocale( String langCode ) : Object
<static> Parses a language code string such as "de_CH" and returns an object with
language and country extracte...
<static> Parses a language code string such as "de_CH" and returns an object with
language and country extracted. The delimiter can be "_" or "-".
|
I18n |
| |
I18n.setLocale( String/Function locale ) : void
<static> Sets the current locale.
<static> Sets the current locale.
|
I18n |
| |
I18n.setUrlPrefix( String prefix ) : void
<static> Sets the prefix for the URL used to request dictionaries from
the server. The locale and URL suffix wi...
<static> Sets the prefix for the URL used to request dictionaries from
the server. The locale and URL suffix will be appended.
Parameters:
prefix : StringThe URL prefix
Returns:
|
I18n |
| |
I18n.setUrlSuffix( String suffix ) : void
<static> Sets the suffix for the URL used to request dictionaries from
the server. It will be appended to the U...
<static> Sets the suffix for the URL used to request dictionaries from
the server. It will be appended to the URL prefix and locale.
Parameters:
suffix : StringThe URL suffix
Returns:
|
I18n |
Public Events
This class has no public events.