Translations in CloudCode
The same translation files used in the application can be used in CloudCode, although the translation function itself is not provided currently.
Step 1: Add the js-yaml library
Use the instructions in CloudCode Dependencies to add the js-yaml library to the task:
yarn add js-yaml
Step 2: Read the file
const fs = require('fs');
const yaml = require('js-yaml');
export async function run() {
const language = 'en_US';
const doc = yaml.safeLoad(fs.readFileSync(`app/translations/${language}.yml`, 'utf8'));
console.log(doc);
}
The translation document can now be used inside the task.
Further reading:
For more information on how translations work for an app, please read the following documentation:
TranslationsLast updated