43 lines
1.8 KiB
JavaScript
43 lines
1.8 KiB
JavaScript
import { readFileSync } from "node:fs";
|
|
import { join, relative } from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
const root = process.cwd();
|
|
const activeLocales = ["da", "en", "sv", "de", "no"];
|
|
const catalogFiles = [
|
|
...activeLocales.map((locale) => `src/i18n/source/${locale}/phrases/compat/pos/index.json`),
|
|
"src/i18n/source/global/shared/pos/index.json",
|
|
...activeLocales.map((locale) => `src/i18n/generated/${locale}-v2.json`),
|
|
"src/i18n/generated/global-v2.json",
|
|
];
|
|
const suspiciousJsonKeyPattern = /"(?:(?:\\.)|[^"\\])*(?:\?|\uFFFD|\\u[fF]{2}[fF][dD])(?:(?:\\.)|[^"\\])*"\s*:/u;
|
|
|
|
describe("i18n key integrity", () => {
|
|
it("does not contain replacement placeholders in translation key names", () => {
|
|
const failures = catalogFiles.flatMap((file) => {
|
|
const filePath = join(root, file);
|
|
const relativePath = relative(root, filePath);
|
|
const keyPaths = readFileSync(filePath, "utf8")
|
|
.split(/\r?\n/)
|
|
.flatMap((line, index) =>
|
|
suspiciousJsonKeyPattern.test(line) ? [`${relativePath}: line ${index + 1}: ${line.trim()}`] : []
|
|
);
|
|
|
|
return keyPaths;
|
|
});
|
|
|
|
expect(failures).toEqual([]);
|
|
});
|
|
|
|
it("defines other_month in the shared and locale runtime catalogs", () => {
|
|
const globalV2 = JSON.parse(readFileSync(join(root, "src/i18n/generated/global-v2.json"), "utf8"));
|
|
expect(globalV2.shared?.global?.text?.anytime).toBe("@:{'templates.generated.compat.global.text.anytime'}");
|
|
expect(globalV2.shared?.global?.text?.other_month).toBe("@:{'templates.generated.compat.global.text.other_month'}");
|
|
|
|
for (const locale of activeLocales) {
|
|
const localeV2 = JSON.parse(readFileSync(join(root, `src/i18n/generated/${locale}-v2.json`), "utf8"));
|
|
expect(localeV2.templates?.generated?.compat?.global?.text?.other_month).toBeDefined();
|
|
}
|
|
});
|
|
});
|