-
Notifications
You must be signed in to change notification settings - Fork 59
/
destructure.js
33 lines (29 loc) · 1.23 KB
/
destructure.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
// For a description of our Transifex workflow and how this script fits into it,
// see CONTRIBUTING.md.
const fs = require('fs');
const { destructure, readSourceMessages, rekeyTranslations, writeTranslations } = require('../util/transifex');
const { logThenThrow, mapComponentsToFiles } = require('../util/util');
const filenamesByComponent = mapComponentsToFiles('src/components');
const { messages: sourceMessages, transifexPaths } = readSourceMessages(
'src/locales',
filenamesByComponent
);
for (const basename of fs.readdirSync('transifex')) {
// Skip .DS_Store and other dot files.
if (basename.startsWith('.')) continue; // eslint-disable-line no-continue
const match = basename.match(/^strings_([-\w]+)\.json$/);
if (match == null) logThenThrow(basename, 'invalid filename');
const locale = match[1];
console.log(`destructuring ${locale}`); // eslint-disable-line no-console
const json = fs.readFileSync(`transifex/${basename}`).toString();
const translated = destructure(json, locale);
rekeyTranslations(sourceMessages, translated, transifexPaths);
writeTranslations(
locale,
sourceMessages,
translated,
'src/locales',
filenamesByComponent
);
}
console.log('done'); // eslint-disable-line no-console