Skip to content

Instantly share code, notes, and snippets.

@indatawetrust
Last active August 4, 2020 16:44
Show Gist options
  • Save indatawetrust/afd186ecd5e85009a144dc18f2477778 to your computer and use it in GitHub Desktop.
Save indatawetrust/afd186ecd5e85009a144dc18f2477778 to your computer and use it in GitHub Desktop.
fix-translate.js
const { set, get } = require('lodash')
const tr = require('./public/locales/tr/translation.json')
const en = require('./public/locales/en/translation.json')
const fs = require('fs')
const newEn = {}
const keys = []
const walker = (obj, topKey) => {
for (let [key, value] of Object.entries(obj)) {
key = topKey ? `${topKey}.${key}` : key;
if (typeof value === "string") {
keys.push(key)
}
else {
walker(value, key)
}
}
}
walker(tr)
if (!keys.some(key => !!get(tr, key))) {
process.exit()
}
for (let key of keys) {
if (get(en, key)) {
set(newEn, key, get(en, key))
}
else {
set(newEn, key, `TÜRKÇESİ: ${get(tr, key)}`)
console.log(get(tr, key))
}
}
fs.writeFileSync('en.json', JSON.stringify(newEn, null, 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment