39 lines
1.2 KiB
JavaScript
39 lines
1.2 KiB
JavaScript
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")));
|
|
});
|