Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
mist-i18n-update-script.js
/**
* This script will update Mist's i18n files
* - adds missing english strings to all translations
* - removes obsolet keys from translations
*/
/* eslint-disable */
const fs = require('fs')
const compare = require('json-structure-diff').compareJSONObjects;
const mistEN = require('./interface/i18n/mist.en.i18n.json');
const appEN = require('./interface/i18n/app.en.i18n.json');
['mist', 'app'].forEach((mode) => {
const en = {
parent: 'en',
content: eval(`${mode}EN`)
};
const files = fs.readdirSync('./interface/i18n')
files.forEach((file) => {
if (file.indexOf(`${mode}`) !== -1 && file.indexOf(`${mode}.en`) === -1) {
const langJson = require(`./interface/i18n/${file}`);
const lang = {
parent: 'lang',
content: langJson
};
let error;
// remove unnecessary keys
error = compare([lang, en])
if (error) {
error.forEach((diff) => {
if (diff.typeOfComparedParent === 'undefined') {
eval(`delete lang.content.${diff.parent.slice(diff.parent.indexOf('.') + 1)}`);
}
});
}
// add missing keys
error = compare([en, lang]);
if (error) {
error.forEach((diff) => {
if (diff.typeOfComparedParent !== diff.typeOfParent && diff.parent !== 'en.mist.applicationMenu.view.languages' && diff.parent !== 'en.mist.applicationMenu.view.langCodes') {
eval(`lang.content.${diff.comparedParent.slice(diff.comparedParent.indexOf('.') + 1)} = en.content.${diff.parent.slice(diff.parent.indexOf('.') + 1)}`);
}
});
}
fs.writeFile(`./interface/i18n/${file}`, JSON.stringify(lang.content, null, 4));
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.