Translation helper class
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)
}
}
}