Skip to main content
TranslationManager wraps i18next and adds helpers for loading translations from MastermindCMS.

Initialization

Before you use translate(), set the locales JSON path once:
In an application, point the path to public locale files:
The {{lng}} placeholder is replaced with the current language. Initialize it once when the application starts.

Exports

From msm-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

Load several values at once:
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.