-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-translations.js
52 lines (43 loc) · 1.35 KB
/
build-translations.js
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
const translationsSource = 'languages/translations.csv';
const translationsTarget = 'app/components/data/translations.js';
const translations = {
en: {},
pt: {}
}
const fs = require('fs');
const csv = require('csv-parse');
console.log('Reading translations from ' + translationsSource + '...');
fs.readFile(translationsSource, function read(error, data) {
if (error) throw error;
console.log('Parsing translations...');
csv.parse(data, {
bom: true,
columns: true,
comment: '#',
delimiter: ';',
ltrim: true,
rtrim: true,
skip_empty_lines: true,
skip_lines_with_empty_values: true,
skip_lines_with_errors: true
}, function (error, records) {
if (error) console.log(error);
console.log('Extracting translations...');
for (const record of records) {
if (record.key && record.key !== '') {
translations.en[record.key] = record.english;
translations.pt[record.key] = record.portuguese || record.english; // I.e. if there is no pt translation, use the en string.
}
}
console.log('Writing translations to ' + translationsTarget);
fs.writeFile(
translationsTarget,
`export default ${JSON.stringify(translations, null, 2)}`,
'utf-8',
(error) => {
if (error) throw error;
console.log('Done.');
}
);
});
});