mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
完善翻译,添加翻译缺失检查工具
This commit is contained in:
1 parent
82c193b5ee
commit
13e3e0ec98
19 files changed
+242
-90
No files matched your search
@@ -0,0 +1,61 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const yaml = require('js-yaml');
|
||||
|
||||
const IGNORE_CHECK = ['en'];
|
||||
const RE_TEXT = /_\(['"]([\s\S])*?['"]\)/gmi;
|
||||
const TEMPLATE_ROOT = path.resolve(__dirname, '..', 'templates');
|
||||
const LOCALE_ROOT = path.resolve(__dirname, '..', 'locales');
|
||||
|
||||
const texts = {};
|
||||
let currentFile = '';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
function _(str) {
|
||||
if (!texts[str]) texts[str] = [currentFile];
|
||||
else texts[str].push(currentFile);
|
||||
}
|
||||
|
||||
function scan(folder, relative = '') {
|
||||
const files = fs.readdirSync(folder);
|
||||
for (const file of files) {
|
||||
const p = path.join(folder, file);
|
||||
if (fs.statSync(p).isDirectory()) {
|
||||
scan(p, path.join(relative, file));
|
||||
} else {
|
||||
currentFile = path.join(relative, file);
|
||||
const f = fs.readFileSync(p).toString();
|
||||
f.replace(RE_TEXT, (substr) => {
|
||||
try {
|
||||
// eslint-disable-next-line no-eval
|
||||
eval(substr);
|
||||
} catch (e) {
|
||||
console.error('Cannot parse: ', substr, ' in file ', p);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
scan(TEMPLATE_ROOT);
|
||||
|
||||
const result = {};
|
||||
|
||||
const locales = fs.readdirSync(LOCALE_ROOT);
|
||||
for (const locale of locales) {
|
||||
if (!IGNORE_CHECK.includes(locale.split('.')[0])) {
|
||||
const p = path.join(LOCALE_ROOT, locale);
|
||||
const f = fs.readFileSync(p).toString();
|
||||
const l = yaml.safeLoad(f);
|
||||
for (const str in texts) {
|
||||
if (!l[str]) {
|
||||
if (result[str]) result[str].locale.push(locale);
|
||||
else result[str] = { str, source: texts[str], locale: [locale] };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`${Object.keys(result).length} translations missing.`);
|
||||
fs.writeFileSync(path.join(__dirname, '..', '__result.json'), JSON.stringify(result, null, 2));
|
||||
console.log(`result wrote to ${path.resolve(__dirname, '..', '__result.json')}`);
|
||||
+1
-1
@@ -5,7 +5,7 @@ async function install() {
|
||||
if (!global.Hydro) throw new Error('Data missing');
|
||||
if (!fs.existsSync('hydro')) fs.mkdirSync('hydro');
|
||||
const hydro = JSON.parse(zlib.gunzipSync(global.Hydro).toString());
|
||||
fs.writeFileSync('development.js', hydro.app);
|
||||
fs.writeFileSync('app.js', hydro.app);
|
||||
for (const i in hydro.modules) {
|
||||
fs.writeFileSync(`${i}.hydro`, Buffer.from(hydro.modules[i], 'base64'));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user