feat: update structure of i18n
This commit is contained in:
parent
a48320862c
commit
0f075e9f7f
12 changed files with 139 additions and 28 deletions
41
generator.js
Normal file
41
generator.js
Normal file
|
@ -0,0 +1,41 @@
|
|||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const translationsDir = './merged';
|
||||
|
||||
const outputFile = 'translations.generated.json';
|
||||
|
||||
function listJsonFiles(dir, prefix = '') {
|
||||
let files = fs.readdirSync(dir);
|
||||
let result = {};
|
||||
|
||||
files.forEach(file => {
|
||||
let fullPath = path.join(dir, file);
|
||||
let stat = fs.statSync(fullPath);
|
||||
|
||||
if (stat.isDirectory()) {
|
||||
let subPrefix = prefix ? `${prefix}.${file}` : file;
|
||||
Object.assign(result, listJsonFiles(fullPath, subPrefix));
|
||||
} else if (file.endsWith('.json')) {
|
||||
let key = `${prefix}.${path.basename(file, '.json')}`;
|
||||
result[key] = fullPath;
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function generateTranslationsIndex() {
|
||||
let translations = {};
|
||||
let files = listJsonFiles(translationsDir);
|
||||
|
||||
Object.entries(files).forEach(([key, filePath]) => {
|
||||
let content = JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
||||
translations[key] = content;
|
||||
});
|
||||
|
||||
fs.writeFileSync(outputFile, JSON.stringify(translations, null, 4), 'utf8');
|
||||
console.log(`Translations index generated: ${outputFile}`);
|
||||
}
|
||||
|
||||
generateTranslationsIndex();
|
Loading…
Add table
Add a link
Reference in a new issue