TranslationManager wraps i18next and adds helpers for loading translations from MastermindCMS.
Initialization
Before you usetranslate(), set the locales JSON path once:
{{lng}} placeholder is replaced with the current language. Initialize it once when the application starts.
Exports
Frommsm-components you can use:
setLocalesPath(loadPath)translate(...args)translations(a proxy for lazy translation access)tr(key, repository?)(loads/returns a single translation)loadTranslation(key, repository?)loadManyTranslations(...keys)loadByLangCodeForEntity(entityId, lang, repository?)loadByLangCode(key, lang)loadTranslationById(id)clearTranslationsCache()getLanguages()getAlphabetForActiveLanguage()
Examples
tr and translations lazily load values from the translation repository:
Notes
- If
setLocalesPath()was not called, translation functions throw an error to make the misconfiguration obvious. - The helper uses the unified service call mechanism under the hood (service/repository calls), so it relies on the built-in client instance provided by
msm-components. - Use
clearTranslationsCache()when the active locale data has changed.