peppa/packages/testkit/test/i18n-kk.test.ts
Асель d674f63567 PEP-99: WIP Kazakh dictionary skeleton on top of PEP-98 i18n (kk sections, coverage test)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 23:07:30 +05:00

40 lines
2.5 KiB
TypeScript
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.

// PEP-99: Kazakh interface — the kk dictionary covers every key of the English one (the
// complete dictionary of PEP-98) with the same placeholders, and kk renders in Kazakh.
import { test } from "node:test";
import assert from "node:assert/strict";
import { dictionary, intlLocale, localizeText, t, translator } from "@peppa/shared/i18n";
const placeholders = (s: string) => [...s.matchAll(/\{(\w+)\}/g)].map((m) => m[1]).sort().join(",");
test("Полнота: у казахского словаря есть все ключи английского", () => {
const en = dictionary("en");
const kk = dictionary("kk");
const missing = Object.keys(en).filter((k) => kk[k] === undefined);
assert.deepEqual(missing, [], `нет казахского перевода: ${missing.slice(0, 20).join(" | ")}`);
});
test("Граница: лишних ключей и чужих плейсхолдеров в казахском словаре нет", () => {
const en = dictionary("en");
const kk = dictionary("kk");
const extra = Object.keys(kk).filter((k) => en[k] === undefined);
assert.deepEqual(extra, [], `ключи, которых нет в коде: ${extra.slice(0, 20).join(" | ")}`);
const bad = Object.entries(kk).filter(([k, v]) => placeholders(k) !== placeholders(v));
assert.deepEqual(bad, [], "плейсхолдеры перевода не совпадают с ключом");
const empty = Object.entries(kk).filter(([, v]) => !v.trim());
assert.deepEqual(empty, []);
});
test("Казахский интерфейс: перевод, название, локаль дат", () => {
assert.equal(t("kk", "Ошибка: {message}", { message: "x" }), "Қате: x");
assert.equal(t("kk", "Пеппа"), "Пеппа ЗАВОД");
assert.equal(intlLocale("kk"), "kk-KZ");
const tr = translator("kk");
assert.equal(tr.n(3, "{n} вопрос ждёт тебя", "{n} вопроса ждут тебя", "{n} вопросов ждут тебя"), "3 сұрақ сізді күтуде");
});
test("Готовый русский текст переводится на казахский, неизвестный остаётся как есть", () => {
assert.equal(localizeText("kk", "Ошибка: нет связи"), "Қате: нет связи");
assert.equal(localizeText("kk", "Совсем неизвестная фраза"), "Совсем неизвестная фраза");
assert.equal(localizeText("ru", "Ошибка: x"), "Ошибка: x");
});