gamebrary/build/translate.js

27 lines
995 B
JavaScript
Raw Normal View History

2019-06-18 23:48:29 +00:00
/* eslint-disable */
2019-06-18 23:46:15 +00:00
const fs = require('fs');
const translate = require('translate-json-object')();
const baseJson = require('../src/i18n/en.json');
2019-06-18 23:46:15 +00:00
2020-11-04 06:03:24 +00:00
// NOTE: Please be careful using you api key, translating the entire app to all languages can get costly
2020-10-08 18:11:07 +00:00
translate.init({ googleApiKey: 'GOOGLE_TRANSLATE_API_KEY' });
2019-06-18 23:46:15 +00:00
2021-02-19 19:44:13 +00:00
const supportedLanguages = ['ar','zh-CN','en','fr','de','it','ja','pt','ru','es'];
2019-06-18 23:46:15 +00:00
for (let i = 0, promise = Promise.resolve(); i < supportedLanguages.length; i++) {
promise = promise.then(() => new Promise(resolve => {
const language = supportedLanguages[i];
translate.translate(baseJson, language)
.then((data) => {
fs.writeFile(`src/i18n/${language}.json`, JSON.stringify(data, null, 4), () => {
2019-06-18 23:46:15 +00:00
console.log(`Translation to ${language} completed`);
resolve();
});
}).catch((err) => {
console.log('error ', err)
});
}));
}