mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 17:41:51 +00:00
5f0865a476
The ratchet excused any value equal to en that held at most one plain word, so "Settings", "Appearance", "Readability" or "Users" copied into another locale were never counted, Japanese and Arabic included. Buttons, tabs and section titles are mostly one word, so a feature could still add 26 English copies of its labels and stay green. An identical value is now excused only when nothing ordinary is left after dropping placeholders, markup, addresses, a listed set of product names (BRAND_NAMES, which now holds one-word names such as Atlas, Immich and Mapbox) and unit symbols (UNITS). A word that really is the locale's own, German "Status" or French "Transport", carries a `// same-as-en` marker on its declaration, which the catalogue reader now reports. The marker is honoured only in Latin-script locales: a Latin word left in Japanese or Russian is English whatever it says. Every locale folder must be on LATIN_LOCALES or NON_LATIN_LOCALES, so a new language cannot pass the rule unclassified. The baseline is re-recorded from the narrower rule: the unmarked copies go from 1252 to 3238, the marked fallbacks stay at 3157, and no entry went down. This is the measured state under the new rule, not a raised gate; translating, or marking a word that is genuinely the same, lowers it with --update as before.
61 lines
2.5 KiB
TypeScript
61 lines
2.5 KiB
TypeScript
// @ts-expect-error: plain .mjs script with no .d.ts; import as JS module.
|
|
import { listDomainFiles, listLocales, parseCatalog, readCatalog } from '../../scripts/i18n-catalog.mjs';
|
|
|
|
import { describe, it, expect } from 'vitest';
|
|
|
|
/**
|
|
* The reader the i18n scripts (parity, the untranslated ratchet, the client's
|
|
* key check) share. It reads the tables as text, so it sees the
|
|
* `// en-fallback` markers, and it refuses what it cannot read rather than
|
|
* skipping it.
|
|
*/
|
|
const ROOT = new URL('../../scripts/fixtures/i18n/', import.meta.url);
|
|
|
|
type Entry = { key: string; value: string; marked: boolean; same: boolean; line: number };
|
|
|
|
describe('i18n catalogue reader', () => {
|
|
it('reads single-line, wrapped, double-quoted and escaped values with their markers', () => {
|
|
const entries = parseCatalog(
|
|
[
|
|
" 'a.one': 'One',",
|
|
" 'a.two':",
|
|
" 'Two, wrapped', // en-fallback",
|
|
` 'a.three': "It's",`,
|
|
" 'a.four': 'Don\\'t \\u00e9',",
|
|
" 'a.five': 'Status', // same-as-en",
|
|
].join('\r\n'),
|
|
);
|
|
expect(entries.map((e: Entry) => [e.key, e.value, e.marked, e.same])).toEqual([
|
|
['a.one', 'One', false, false],
|
|
['a.two', 'Two, wrapped', true, false],
|
|
['a.three', "It's", false, false],
|
|
['a.four', "Don't é", false, false],
|
|
['a.five', 'Status', false, true],
|
|
]);
|
|
});
|
|
|
|
it('refuses a value that is not one string literal instead of skipping it', () => {
|
|
expect(() => parseCatalog(" 'a.one': 'One' + 'Two',", 'x.ts')).toThrow(
|
|
/x\.ts:1: 'a\.one' is not a single string literal/,
|
|
);
|
|
expect(() => parseCatalog(" 'a.one': `One`,", 'x.ts')).toThrow(/not a single string literal/);
|
|
expect(() => parseCatalog(" 'a.one': 'unterminated,", 'x.ts')).toThrow(/not a single string literal/);
|
|
});
|
|
|
|
it('lists locales and domain files and reads a table from disk', () => {
|
|
expect(listLocales(ROOT).sort()).toEqual(['de', 'en']);
|
|
expect(listDomainFiles('en', ROOT)).toEqual(['a.ts']);
|
|
const de: Entry[] = readCatalog('de', 'a.ts', ROOT);
|
|
expect(de.find((e) => e.key === 'a.lone')).toMatchObject({ value: 'Remove {count} items', marked: true });
|
|
expect(de.find((e) => e.key === 'a.multi')).toMatchObject({
|
|
value: 'A long sentence that wraps onto the next line',
|
|
});
|
|
});
|
|
|
|
it('reads every real locale table', () => {
|
|
for (const locale of listLocales()) {
|
|
for (const file of listDomainFiles(locale)) expect(() => readCatalog(locale, file)).not.toThrow();
|
|
}
|
|
});
|
|
});
|