Hi I had a requirement to generate reports from backend.
I’m using cloud code to generate reports.
I need to use different languages in the reports based on user’s local language.
So can you please let me know how to implement language translations in cloud code.
You can read the translation files in CloudCode using fs
and js-yaml
packages. You can find example code in the documentation. In the example in the documentation, the language
variable is hardcoded. You will rather want to define this dynamically from within the application using journey.locale
(link to documentation). This can be passed into the application in various ways depending on how you are triggering the CloudCode task (e.g., pass as a parameter if triggering the task from within the app or define as a field on the webhook-triggered object).
You will then have access to the translation file in CloudCode (as an object
) where you can display the translated value using the key as you would any other variable defined in CloudCode.
Thanks Jaime.
I’ll try to implement in my application. And let you know asap.