@absolunet/ioc2.1.0

View on GitHub

Translator

Translator that implements i18n basic features.

Extends

Members

(static) dependencies :Array.<string>

Source:
Class dependencies: ['app', 'config'].

locale :string

Source:
Current locale.

fallbackLocale :string

Source:
Current fallback locale.

Methods

(async) loadTranslations()

Source:
Load translations from source.
Returns:
The async process promise.
Type
Promise

translate(string, replacementsopt, countopt)

Source:
Translate a string for the current locale. If replacement object is given, replace placeholders by the given replacement.
Parameters:
Name Type Attributes Default Description
string string The string to translate.
replacements object.<string, string> <optional>
The token replacements.
count number <optional>
1 The string count for pluralization.
Returns:
The translated string.
Type
string

translateForLocale(locale, string, replacementsopt, countopt)

Source:
Translate a string for the given locale.
Parameters:
Name Type Attributes Description
locale string The locale to use for translation.
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:
Add translation key and value for given locale or current locale.
Parameters:
Name Type Default Description
key string The translation key.
value string The translation value.
locale string | null null The locale the translation should be used for.
Returns:
The current translator instance.
Type
translation.services.Translator

addTranslations(translations)

Source:
Add translations from key-value pair object.
Example
translator.addTranslations({
    foo: {
        bar: {
            en: 'baz',
            fr: 'qux'
        }
    }
});
Parameters:
Name Type Description
translations object.<string, object.<string, (object|string)>> Collection of translations.
Returns:
The current translator instance.
Type
translation.services.Translator

setLocale(locale)

Source:
Set locale to use for translation.
Parameters:
Name Type Description
locale string The locale.
Returns:
The current translator instance.
Type
translation.services.Translator

setFallbackLocale(locale)

Source:
Set fallback locale to use if translation in default locale does not exists.
Parameters:
Name Type Description
locale string The fallback locale.
Returns:
The current translator instance.
Type
translation.services.Translator

driver(nameopt, parametersopt)

Source:
Inherited From:
Get loader driver by name.
Parameters:
Name Type Attributes Default Description
name string <optional>
"default" The driver name.
parameters object <optional>
{} The additional parameters to inject into the driver instance.
Returns:
The resolved driver instance.
Type
object

bootDriver(driver, name)

Source:
Overrides:
Boot newly created driver.
Parameters:
Name Type Description
driver * The driver instance.
name string The driver name.
Returns:
The driver instance.
Type
*

addDriver(name, driver)

Source:
Inherited From:
Add a driver and bind it with the given name.
Parameters:
Name Type Description
name string The driver name.
driver function The driver class or factory.

setDefaultDriver(name)

Source:
Inherited From:
Set given driver name as the default driver.
Parameters:
Name Type Description
name string The driver name.

setDriverAlias(name, alias)

Source:
Inherited From:
Give driver an alias name.
Parameters:
Name Type Description
name string The driver name.
alias string The driver alias.

hasDriver(name)

Source:
Inherited From:
Check if driver exists.
Parameters:
Name Type Description
name string The driver name.
Returns:
Indicates that the driver exists.
Type
boolean

isDriverAlias(name)

Source:
Inherited From:
Check if given driver name is an alias.
Parameters:
Name Type Description
name string The driver alias name.
Returns:
Indicates that the alias exists.
Type
boolean