Files
BarevClub/packages/i18n/scripts/export.ts
T

32 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Выгрузка для носителей языка: i18n-review/<lang>.csv
* key, ru, translation, status, approved
* Носитель правит колонку translation и ставит "yes" в approved, затем: pnpm i18n:import <файл>.
*
* pnpm i18n:export — все языки, только needs_review
* pnpm i18n:export -- --all — все ключи
*/
import { mkdirSync, writeFileSync } from 'node:fs';
import path from 'node:path';
import { csvEscape, readLocale, readReview, ROOT, statusOf, TARGETS } from './lib.ts';
const all = process.argv.includes('--all');
const ru = readLocale('ru');
const review = readReview();
const outDir = path.resolve(ROOT, '../../i18n-review');
mkdirSync(outDir, { recursive: true });
for (const locale of TARGETS) {
const msgs = readLocale(locale);
const rows = [['key', 'ru', 'translation', 'status', 'approved']];
for (const [key, source] of Object.entries(ru)) {
const status = statusOf(review, locale, key, source, msgs[key]);
if (!all && status === 'approved') continue;
rows.push([key, source, msgs[key] ?? '', status, '']);
}
const file = path.join(outDir, `${locale}.csv`);
// BOM — чтобы Excel открыл UTF-8 с армянским и китайским
writeFileSync(file, '' + rows.map((r) => r.map(csvEscape).join(',')).join('\n') + '\n');
console.log(`${file}: ${rows.length - 1} строк`);
}