@absolunet/ioc2.1.0

View on GitHub

Driver

Abstract driver that defines the basic interface for a translator driver.

Methods

(async, abstract) loadTranslations()

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

(abstract) translate(string, replacementsopt, countopt)

Source:
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

(abstract) addTranslation(key, value, locale)

Source:
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.
Type
translation.services.Translator.drivers.Driver

(abstract) addTranslations(translations)

Source:
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.
Type
translation.services.Translator.drivers.Driver

(abstract) setLocale(locale)

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

(abstract) setFallbackLocale(locale)

Source:
Set fallback locale.
Parameters:
Name Type Description
locale string The fallback locale.
Returns:
The current driver instance.
Type
translation.services.Translator.drivers.Driver