Apps, web, i18n, UI, partners, payouts, backoffice, bariki, prod infra
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
45d7512d2b
commit
3489e0b816
319 files changed
+45483
-121
No files matched your search
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Загрузка проверенных переводов: pnpm i18n:import -- i18n-review/hy.csv [i18n-review/zh.csv …]
|
||||
* Язык берётся из имени файла. Строки с approved=yes помечаются проверенными для текущего русского текста.
|
||||
*/
|
||||
import { readFileSync } from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { isLocale } from '../src/index.ts';
|
||||
import { parseCsv, placeholders, readLocale, readReview, sourceHash, writeLocale, writeReview } from './lib.ts';
|
||||
|
||||
const files = process.argv.slice(2).filter((a) => !a.startsWith('--'));
|
||||
if (!files.length) {
|
||||
console.error('Укажите CSV-файлы: pnpm i18n:import -- i18n-review/hy.csv');
|
||||
process.exit(1);
|
||||
}
|
||||
const ru = readLocale('ru');
|
||||
const order = Object.keys(ru);
|
||||
const review = readReview();
|
||||
|
||||
for (const file of files) {
|
||||
const locale = path.basename(file, '.csv');
|
||||
if (!isLocale(locale) || locale === 'ru') throw new Error(`Не понимаю язык файла ${file}`);
|
||||
const [header, ...rows] = parseCsv(readFileSync(path.resolve(process.env.INIT_CWD ?? process.cwd(), file), 'utf8').replace(/^\uFEFF/, ''));
|
||||
const col = (name: string) => header!.indexOf(name);
|
||||
const msgs = readLocale(locale);
|
||||
let updated = 0;
|
||||
let approved = 0;
|
||||
for (const r of rows) {
|
||||
const key = r[col('key')]!;
|
||||
const translation = r[col('translation')]?.trim();
|
||||
if (!(key in ru) || !translation) continue;
|
||||
if (placeholders(ru[key]!) !== placeholders(translation)) {
|
||||
console.warn(`${locale}: пропущен ${key} — плейсхолдеры не совпадают с русским`);
|
||||
continue;
|
||||
}
|
||||
if (msgs[key] !== translation) updated++;
|
||||
msgs[key] = translation;
|
||||
if (/^(yes|да|y|1|ok)$/i.test(r[col('approved')]?.trim() ?? '')) {
|
||||
review[locale][key] = sourceHash(ru[key]!);
|
||||
approved++;
|
||||
}
|
||||
}
|
||||
writeLocale(locale, msgs, order);
|
||||
console.log(`${locale}: обновлено ${updated}, проверено ${approved}`);
|
||||
}
|
||||
writeReview(review);
|
||||
Reference in new issue
Block a user