mirror of
https://github.com/QingWei-Li/notea.git
synced 2024-11-29 12:53:00 +03:00
f1898cc133
reformat: All files have been reformatted.
32 lines
1007 B
JavaScript
32 lines
1007 B
JavaScript
const extract = require('i18n-extract');
|
|
const { resolve, extname } = require('path');
|
|
const { sortBy, forEach } = require('lodash');
|
|
const { readdirSync, readFileSync, writeFileSync } = require('fs');
|
|
|
|
console.log(`[i18n] Extracting keys`);
|
|
|
|
const keys = extract.extractFromFiles([resolve(__dirname, '../**/*.tsx')], {
|
|
marker: 't',
|
|
parser: 'typescript',
|
|
});
|
|
const localesPath = resolve(__dirname, '../locales');
|
|
const files = readdirSync(localesPath);
|
|
|
|
forEach(files, (file) => {
|
|
if (extname(file) === '.json') {
|
|
const filePath = resolve(localesPath, file);
|
|
const text = readFileSync(filePath).toString() || `{}`;
|
|
const rawLocale = JSON.parse(text);
|
|
const locale = {};
|
|
|
|
forEach(sortBy(keys, 'key'), ({ key }) => {
|
|
if (!locale[key]) {
|
|
locale[key] = rawLocale[key] || key;
|
|
}
|
|
});
|
|
|
|
writeFileSync(filePath, JSON.stringify(locale, null, ' '));
|
|
console.log(`[i18n] Generated ${file}`);
|
|
}
|
|
});
|