-
Notifications
You must be signed in to change notification settings - Fork 55
/
genlocales
executable file
·47 lines (40 loc) · 1.27 KB
/
genlocales
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
#!/usr/bin/env node
/*
* This Source Code is subject to the terms of the Mozilla Public License
* version 2.0 (the 'License'). You can obtain a copy of the License at
* http://mozilla.org/MPL/2.0/.
*/
/* eslint-env node */
/* eslint-disable no-console */
const fs = require('fs');
const glob = require('glob');
const descRe = /^addon_description= (.*)$/m;
const package = require('./package.json');
let descriptions = {};
glob('locales/*/*.properties', function (err, files) {
if (err) {
return console.error('Error finding files', err);
}
files.forEach(function (path) {
let lang = parseLang(path);
fs.createReadStream(path).pipe(fs.createWriteStream(`locale/${lang}.properties`));
let contents = fs.readFileSync(path, 'utf8');
let match = descRe.exec(contents);
if (match && lang !== 'en-US') {
descriptions[lang] = {'description': match[1]};
}
if (lang === 'en-US') {
fs.createReadStream(path).pipe(fs.createWriteStream(`locale/en.properties`));
}
});
package.locales = descriptions;
fs.writeFile('./package.json', JSON.stringify(package, null, 2), function (err) {
if (err) {
console.log(err);
}
});
});
function parseLang(path) {
const segments = path.split('/');
return segments[segments.length - 2];
}