-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessFile.js
More file actions
71 lines (63 loc) · 2.5 KB
/
processFile.js
File metadata and controls
71 lines (63 loc) · 2.5 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
71
const fs = require('fs');
let language_code = 'en'; // en, de, el, es, fr, it, ja, ko, pt-PT, zh-CN
process.argv.forEach((val, index) => {
if (index === 2) {
language_code_arr = ['en', 'de', 'el', 'es', 'fr', 'it', 'ja', 'ko', 'pt-PT', 'zh-CN'];
if (language_code_arr.includes(val)) {
language_code = val;
} else {
throw new Error('Unrecognised language!');
}
}
});
// set the file you want to process
const mobile_app_strings = require(`./translated_strings/en/mobile_app_strings`);
const all_strings = require(`./translated_strings/${language_code}/all_strings`);
// set the output file names
const process_result_file = 'mobile_app_strings_translated.json';
const process_result_file_2 = 'mobile_app_strings_to_be_translated.json';
fs.appendFile(`./translated_strings/${language_code}/${process_result_file}`,'{\n', (err)=>{
if (err) throw err;
// console.log('process_result_file { is appended!');
});
fs.appendFile(`./translated_strings/${language_code}/${process_result_file_2}`,'{\n', (err)=>{
if (err) throw err;
// console.log('process_result_file_2 { is appended!');
});
for (var key in mobile_app_strings) {
if (mobile_app_strings.hasOwnProperty(key)) {
// check if the key exits in old translation file
let keyFound = false;
let keyValue = '';
for (var keyRaw in all_strings) {
if (all_strings.hasOwnProperty(keyRaw)) {
if ( key.toLowerCase() === keyRaw.toLowerCase() ) {
keyFound = true;
keyValue = all_strings[keyRaw];
var stringToPrint = '"' + key + '"' + ': ' + '"' + keyValue + '"' + ',\n';
fs.appendFile(`./translated_strings/${language_code}/${process_result_file}`,stringToPrint, (err)=>{
if (err) throw err;
// console.log('all_strings { is appended!');
});
}
}
}
// key does not exist
if (keyFound === false) {
keyValue = mobile_app_strings[key];
var string2ToPrint = '"' + key + '"' + ': ' + '"' + keyValue + '"' + ',\n';
fs.appendFile(`./translated_strings/${language_code}/${process_result_file_2}`,string2ToPrint, (err)=>{
if (err) throw err;
// console.log('all_strings { is appended!');
});
}
}
}
fs.appendFile(`./translated_strings/${language_code}/${process_result_file}`,'}', (err)=>{
if (err) throw err;
// console.log('all_strings } is appended!');
});
fs.appendFile(`./translated_strings/${language_code}/${process_result_file_2}`,'}', (err)=>{
if (err) throw err;
// console.log('all_strings } is appended!');
});