Last active
August 4, 2020 16:44
-
-
Save indatawetrust/afd186ecd5e85009a144dc18f2477778 to your computer and use it in GitHub Desktop.
fix-translate.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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