-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeduplicate.js
More file actions
46 lines (36 loc) · 1.17 KB
/
deduplicate.js
File metadata and controls
46 lines (36 loc) · 1.17 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
/*
* Read in en.default.schema.json
* output en.dictionary.json which is all translateable strings mapped to themselves as keys
* */
const glob = require('glob');
const fs = require('fs');
const path = require('path');
const filePatterns = [
'./sections/**/default/locales/en.default.schema.json',
'./components/**/default/locales/en.default.schema.json',
'./blocks/**/default/locales/en.default.schema.json',
'./source/locales/en.default.schema.json',
]
let dictionary = {};
if (fs.existsSync('./en.dictionary.json')) {
dictionary = JSON.parse(fs.readFileSync('./en.dictionary.json'));
}
function buildDict(obj) {
Object.keys(obj).forEach(key => {
if (typeof(obj[key]) === 'string') {
dictionary[obj[key]] = obj[key];
} else {
buildDict(obj[key]);
}
});
}
filePatterns.forEach(pattern => {
const files = glob.sync(pattern);
files.forEach(file => {
const localeContent = JSON.parse(fs.readFileSync(file));
buildDict(localeContent);
});
});
const dictString = JSON.stringify(dictionary, Object.keys(dictionary).sort(), 2);
//const dictString = JSON.stringify(dictionary, null, 2);
fs.writeFileSync('en.dictionary.json', dictString);