Skip to content

Translation helper class

Compare
Choose a tag to compare
@hideokamoto hideokamoto released this 31 Oct 06:33
· 198 commits to master since this release

Add Translation helper class.
Docs: https://ask-utils.github.io/ask-utils/Translations.html

Usage

const LocalizationInterceptor = {
  process (handlerInput) {
   const t = new Translations()
   t.putLocaleStrings('en-US', {
    HELLO: 'Hello'
   })
   t.putLocaleStrings('ja-JP', {
    HELLO: 'こんにちは'
   })
   
    const localizationClient = i18n.use(sprintf).init({
      lng: handlerInput.requestEnvelope.request.locale,
      overloadTranslationOptionHandler: sprintf.overloadTranslationOptionHandler,
      resources: t.getLanguageStrings(),
      returnObjects: true
    })

    const attributes = handlerInput.attributesManager.getRequestAttributes()
    attributes.t = function (...args) {
      return localizationClient.t(...args)
    }
  }
}