2020-09-06 16:15:25 +00:00
|
|
|
fs = require('fs');
|
|
|
|
|
2020-09-10 19:22:21 +00:00
|
|
|
let translationDir = 'lemmy-translations/translations/';
|
2020-09-06 16:15:25 +00:00
|
|
|
let outDir = 'src/shared/translations/';
|
|
|
|
fs.mkdirSync(outDir, { recursive: true });
|
2021-01-06 21:06:13 +00:00
|
|
|
fs.readdir(translationDir, (_err, files) => {
|
2020-09-06 16:15:25 +00:00
|
|
|
files.forEach(filename => {
|
|
|
|
const lang = filename.split('.')[0];
|
|
|
|
try {
|
|
|
|
const json = JSON.parse(
|
|
|
|
fs.readFileSync(translationDir + filename, 'utf8')
|
|
|
|
);
|
|
|
|
var data = `export const ${lang} = {\n translation: {`;
|
|
|
|
for (var key in json) {
|
|
|
|
if (key in json) {
|
|
|
|
const value = json[key].replace(/"/g, '\\"');
|
|
|
|
data = `${data}\n ${key}: "${value}",`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
data += '\n },\n};';
|
|
|
|
const target = outDir + lang + '.ts';
|
|
|
|
fs.writeFileSync(target, data);
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|