@absolunet/ioc2.1.0

View on GitHub

FileDriver

File driver to handle translations.

Extends

Members

(static) dependencies :Array.<string>

Source:
Class dependencies: ['app', 'file', 'helper.string'].

fallbackLocale :string

Source:
The fallback locale.

folder :string

Source:
The folder in which the translations are stored.

defaultNamespace :string

Source:
The default namespace for translations.

Methods

ensureTranslationsAreLoaded()

Source:
Ensure that the translations are loaded from configured path.
Returns:
The current driver instance.
Type
translation.services.Translator.drivers.FileDriver

getTranslationForLocale(key, locale)

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

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

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

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

setLocale(locale)

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

setFallbackLocale(locale)

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