NodeJS Translation module, that can be used for Agents like Actions On Google or Dialogflow Fulfillment Library
This module is a basic nodejs module allowing you to handle translations for your app. The specificity is that you can easily handle multiple translation values for 1 given key. In that case, the module will return randomly one of the value. This is quite usefull for creation of an agent app with Dialogflow Fulfillment Library, or Actions of Google for example.
├── src/│ ├── locales/│ │ ├── fr-fr.json│ │ └── en-us.json
Then you can use it easily :
translate("KEY_1")
==> "Hey, this is my translation key for key 1"
or
translate("KEY_2")
==> returns randomly "Ok, I am first translation option for key 2" or "Hey, I am the second option for key 2", or "yop... and I am... well... the third option"
npm
npm install agent-translate
usage
const translate = ; const i18n = translate; return ;
options
translate
const i18n = translate.init('en-us');
=> will look for 'my/specific/locales/directory/en-us.json
const i18n2 = translate.init('fr-fr');
=> will look for 'my/specific/locales/directory/fr-fr.json
const i18n3 = translate.init('unknown');
=> will look for 'my/specific/locales/directory/en-us.json', set here as 'default_locale
dialogflow-fulfillment-nodejs
usage withconst translate = ; exportsmyAssistantWebhook = functionshttps