Extends
Members
(static) dependencies :Array.<string>
Class dependencies:
['app', 'file', 'helper.string']
.
fallbackLocale :string
The fallback locale.
folder :string
The folder in which the translations are stored.
defaultNamespace :string
The default namespace for translations.
Methods
ensureTranslationsAreLoaded()
Ensure that the translations are loaded from configured path.
Returns:
The current driver instance.
getTranslationForLocale(key, locale)
Get unparsed translation value(s) for given locale.
It will use fallback locale if needed.
Parameters:
Name | Type | Description |
---|---|---|
key |
string | The translation key. |
locale |
string | The locale. |
Returns:
The translated value.
- Type
- string
parse(string, replacementsopt, countopt)
Parse given string with the given token replacements.
Handle manual pluralization based on a given count.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
string |
string | Array.<string> | The value. | ||
replacements |
object.<string, string> |
<optional> |
The token replacement dictionary. | |
count |
number |
<optional> |
1
|
The count for pluralization. |
Returns:
The parsed string.
- Type
- string
buildReplacementPattern(token)
Build the replacement pattern from a given token name.
Parameters:
Name | Type | Description |
---|---|---|
token |
string | The token to replace. |
Returns:
The token pattern.
- Type
- string
(async) loadTranslations()
- Source:
- Overrides:
Load translations from source.
Returns:
The possible async process promise.
- Type
- Promise | void
translate(string, replacementsopt, countopt)
- Source:
- Overrides:
Translate a string for the current locale.
If replacement array is given, replace %s by the given replacement in order of appearance.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
string |
string | The string to translate. | |
replacements |
object.<string, string> |
<optional> |
The token replacements. |
count |
number |
<optional> |
The string count for pluralization. |
Returns:
The translated string.
- Type
- string
addTranslation(key, value, locale)
- Source:
- Overrides:
Add translation key and value for given locale or current locale.
Parameters:
Name | Type | Description |
---|---|---|
key |
string | The translation key. |
value |
string | The translation value. |
locale |
string | null | The locale the translation should be used for. |
Returns:
The current driver instance.
addTranslations(translations)
- Source:
- Overrides:
Add translations from key-value pair object.
Example
driver.addTranslations({
foo: {
bar: {
en: 'baz',
fr: 'qux'
}
}
});
Parameters:
Name | Type | Description |
---|---|---|
translations |
string | The translations. |
Returns:
The current driver instance.
setLocale(locale)
- Source:
- Overrides:
Set locale to use for translation.
Parameters:
Name | Type | Description |
---|---|---|
locale |
string | The locale. |
Returns:
The current driver instance.
setFallbackLocale(locale)
- Source:
- Overrides:
Set fallback locale.
Parameters:
Name | Type | Description |
---|---|---|
locale |
string | The fallback locale. |
Returns:
The current driver instance.