-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcopy-translation-to-csv.js
More file actions
70 lines (53 loc) · 1.95 KB
/
copy-translation-to-csv.js
File metadata and controls
70 lines (53 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const localeFolder = './src/assets/locale/';
const fs = require('fs');
const readline = require('readline');
const enLocaleFile = './src/assets/locale/en.json';
const deLocaleFile = './src/assets/locale/de.json';
const rwLocaleFile = './src/assets/locale/rw.json';
var enJSON = JSON.parse(fs.readFileSync(enLocaleFile));
var deJSON = JSON.parse(fs.readFileSync(deLocaleFile));
var rwJSON = JSON.parse(fs.readFileSync(rwLocaleFile));
const csvFile = './src/assets/locale/translations-Table.txt'; //copy from google sheets to semicolon separated file and remove header
const readTranslations = readline.createInterface({
input: fs.createReadStream(csvFile),
output: process.stdout,
terminal: false
});
let data = enJSON.translations;
let keys = Object.keys(data);
let changed = {};
(async () => {
readTranslations.on('line', (line) => {
splitLine = line.split(';');
id = splitLine[0];
en = splitLine[1];
// console.log(id)
if (data[id] && data[id].trim() != en) {
if (id != "cookies.cookiePage"
&& id != "privacy.PrivacyPolicyPage"
&& id != "terms.termAndConditionsPage"
&& id != "productLabel.labelsInfo.messageWithLink"
&& id != "welcomeScreen.modal.bodyText"
&& id != "ui.attachmentUploader.nalozeno") {
changed[id] = {pr: en, now: data[id]};
console.log("*** ", id)
console.log("PR:", en)
console.log("NO:", data[id])
}
// console.log(changed)
}
})
})()
csvString = "ID;English;German;Kinyarwanda" + "\n";
for (let key of keys) {
csvString += key + ";"
csvString += enJSON.translations[key] + ";"
csvString += deJSON.translations[key] + ";"
csvString += rwJSON.translations[key] + "\n"
}
var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0');
var yyyy = today.getFullYear();
today = mm + '-' + dd + '-' + yyyy;
fs.writeFileSync(localeFolder + 'tr_' + today + '.csv', csvString);