mirror of
https://github.com/Qortal/qapp-core.git
synced 2026-04-27 02:49:23 +00:00
57 lines
1.4 KiB
JavaScript
Executable File
57 lines
1.4 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
const fg = require('fast-glob');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const LOCALES_DIR = path.resolve(__dirname, '../src/i18n/locales');
|
|
const OUTPUT_FILE = path.join(__dirname, '../src/i18n/compiled-i18n.json');
|
|
|
|
(async () => {
|
|
const files = await fg('**/*.json', { cwd: LOCALES_DIR, absolute: true });
|
|
|
|
const resources = {};
|
|
const supportedLanguages = new Set();
|
|
|
|
for (const filePath of files) {
|
|
const parts = filePath.split(path.sep);
|
|
const lang = parts[parts.length - 2];
|
|
const ns = path.basename(filePath, '.json');
|
|
|
|
supportedLanguages.add(lang);
|
|
|
|
const json = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
|
|
|
if (!resources[lang]) resources[lang] = {};
|
|
resources[lang][ns] = json;
|
|
}
|
|
|
|
const sortedLanguages = Array.from(supportedLanguages).sort();
|
|
const sortedResources = sortedLanguages.reduce((acc, lang) => {
|
|
const namespaces = resources[lang] || {};
|
|
const sortedNamespaces = Object.keys(namespaces)
|
|
.sort()
|
|
.reduce((nsAcc, ns) => {
|
|
nsAcc[ns] = namespaces[ns];
|
|
return nsAcc;
|
|
}, {});
|
|
acc[lang] = sortedNamespaces;
|
|
return acc;
|
|
}, {});
|
|
|
|
// Save compiled resources and languages
|
|
fs.writeFileSync(
|
|
OUTPUT_FILE,
|
|
JSON.stringify(
|
|
{
|
|
resources: sortedResources,
|
|
supportedLanguages: sortedLanguages,
|
|
},
|
|
null,
|
|
2
|
|
)
|
|
);
|
|
|
|
console.log('✅ i18n resources generated.');
|
|
})();
|