build: reject duplicate generated translations
This commit is contained in:
38
webui/tests/i18n-catalog-validation.test.mjs
Normal file
38
webui/tests/i18n-catalog-validation.test.mjs
Normal file
@@ -0,0 +1,38 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
import { findDuplicateTranslationKeys } from "../scripts/i18n-catalog-validation.mjs";
|
||||
|
||||
test("allows the same translation key once in each locale", () => {
|
||||
const source = `
|
||||
export const generatedTranslations = {
|
||||
en: { "i18n:example.share.12345678": "Share" },
|
||||
de: { "i18n:example.share.12345678": "Freigeben" }
|
||||
};
|
||||
`;
|
||||
|
||||
assert.deepEqual(findDuplicateTranslationKeys(source), []);
|
||||
});
|
||||
|
||||
test("rejects duplicate keys within a generated locale catalog", () => {
|
||||
const source = `
|
||||
export const generatedTranslations = {
|
||||
en: {
|
||||
"i18n:example.share.12345678": "Share",
|
||||
"i18n:example.share.12345678": "Share"
|
||||
},
|
||||
de: {
|
||||
"i18n:example.share.12345678": "Freigabe",
|
||||
"i18n:example.share.12345678": "Freigeben"
|
||||
}
|
||||
};
|
||||
`;
|
||||
|
||||
const findings = findDuplicateTranslationKeys(source, "fixture.ts");
|
||||
|
||||
assert.equal(findings.length, 2);
|
||||
assert.match(findings[0], /fixture\.ts:\d+:\d+ duplicate generated translation key/);
|
||||
assert.match(findings[0], /locale "en"/);
|
||||
assert.match(findings[1], /locale "de"/);
|
||||
assert.ok(findings.every((finding) => finding.includes("first declared at line")));
|
||||
});
|
||||
Reference in New Issue
Block a user