dika/scripts/check-i18n.js

18 lines
1.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import fs from "node:fs";
const keys = (l) => Object.keys(JSON.parse(fs.readFileSync(`public/i18n/${l}.json`, "utf8"))).sort().join();
const ru = keys("ru");
for (const l of ["kk", "en"]) if (keys(l) !== ru) { console.error(`i18n: ключи ${l} не совпадают с ru`); process.exit(1); }
console.log("i18n ok");
// Каждая акция из базы должна быть переведена на kk и en, иначе на экране смесь языков.
const csv = fs.readFileSync("data/venues.csv", "utf8").split(/\r?\n/).slice(1).filter(Boolean).map((r) => r.split(";")[10]);
for (const l of ["kk", "en"]) {
const map = JSON.parse(fs.readFileSync(`public/i18n/${l}.json`, "utf8")).promoTexts || {};
for (const p of csv) if (p && p !== "нет" && !map[p]) { console.error(`i18n: акция «${p}» не переведена (${l})`); process.exit(1); }
}
// Каждый текст, на который ссылается страница, должен быть в переводах — иначе кнопка или поле останутся без подписи.
const { pageKeys } = await import("../src/page.js");
const ruAll = JSON.parse(fs.readFileSync("public/i18n/ru.json", "utf8"));
for (const p of ["public/index.html", "public/base.html", "admin/index.html"]) {
for (const k of pageKeys(fs.readFileSync(p, "utf8"))) if (typeof ruAll[k] !== "string" || !ruAll[k]) { console.error(`i18n: на странице ${p} нет текста для «${k}»`); process.exit(1); }
}