mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 02:34:21 +00:00
fix(i18n): a one-word English copy counts as untranslated
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.
This commit is contained in:
@@ -11,7 +11,7 @@ import { describe, it, expect } from 'vitest';
|
||||
*/
|
||||
const ROOT = new URL('../../scripts/fixtures/i18n/', import.meta.url);
|
||||
|
||||
type Entry = { key: string; value: string; marked: boolean; line: number };
|
||||
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', () => {
|
||||
@@ -22,13 +22,15 @@ describe('i18n catalogue reader', () => {
|
||||
" '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])).toEqual([
|
||||
['a.one', 'One', false],
|
||||
['a.two', 'Two, wrapped', true],
|
||||
['a.three', "It's", false],
|
||||
['a.four', "Don't é", false],
|
||||
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],
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
compare,
|
||||
countUntranslated,
|
||||
isExcused,
|
||||
isInvariant,
|
||||
lowered,
|
||||
readBaseline,
|
||||
@@ -14,7 +15,7 @@ import { describe, it, expect } from 'vitest';
|
||||
* The untranslated-strings ratchet (scripts/i18n-untranslated.mjs). The
|
||||
* fixtures under scripts/fixtures/ hold a two-locale table with one marked
|
||||
* fallback, two unmarked English copies and the invariant strings the rule
|
||||
* excuses.
|
||||
* excuses; i18n-words/ holds the one-word cases per script.
|
||||
*/
|
||||
const FIXTURES = new URL('../../scripts/fixtures/', import.meta.url);
|
||||
const ROOT = new URL('i18n/', FIXTURES);
|
||||
@@ -22,24 +23,32 @@ const ROOT = new URL('i18n/', FIXTURES);
|
||||
type Counts = Record<string, Record<string, { marked: number; identical: number }>>;
|
||||
|
||||
describe('i18n untranslated ratchet', () => {
|
||||
it('excuses placeholders, codes, names and single words, never a phrase', () => {
|
||||
it('excuses placeholders, codes, units and names, never an ordinary word or a phrase', () => {
|
||||
for (const same of [
|
||||
'{count} km',
|
||||
'{minutes} min',
|
||||
'GPX',
|
||||
'OAuth',
|
||||
'Google Maps',
|
||||
'Atlas',
|
||||
'Mapbox (3D)',
|
||||
'Dawarich {version}',
|
||||
'PDF · {size}',
|
||||
'Budget',
|
||||
'Name (A\u2013Z)',
|
||||
'Check-in',
|
||||
'https://ntfy.sh',
|
||||
'your@email.com',
|
||||
'Update → v{version}',
|
||||
'<b>{name}</b>',
|
||||
]) {
|
||||
expect([same, isInvariant(same)]).toEqual([same, true]);
|
||||
}
|
||||
for (const copy of [
|
||||
'Settings',
|
||||
'Appearance',
|
||||
'Readability',
|
||||
'Budget',
|
||||
'Check-in',
|
||||
'Atlases',
|
||||
'Name (A\u2013Z)',
|
||||
'Update → v{version}',
|
||||
'Trip settings',
|
||||
'Remove {count} items',
|
||||
'Open in Google Maps',
|
||||
@@ -50,6 +59,25 @@ describe('i18n untranslated ratchet', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('honours // same-as-en in a Latin-script locale only, and refuses an unlisted locale', () => {
|
||||
expect(isExcused('Status', true, 'de')).toBe(true);
|
||||
expect(isExcused('Status', false, 'de')).toBe(false);
|
||||
expect(isExcused('Status', true, 'ja')).toBe(false);
|
||||
expect(isExcused('GPX', false, 'ja')).toBe(true);
|
||||
expect(() => isExcused('Status', true, 'xx')).toThrow(/neither LATIN_LOCALES nor NON_LATIN_LOCALES/);
|
||||
});
|
||||
|
||||
it('counts a one-word English copy: Settings in fr, Appearance in ja', () => {
|
||||
expect(countUntranslated(new URL('i18n-words/', FIXTURES))).toEqual({
|
||||
fr: { 'a.ts': { marked: 0, identical: 2 } },
|
||||
ja: { 'a.ts': { marked: 0, identical: 2 } },
|
||||
});
|
||||
});
|
||||
|
||||
it('fails closed on a locale folder on neither script list', () => {
|
||||
expect(() => countUntranslated(new URL('i18n-unlisted/', FIXTURES))).toThrow(/locale xx is on neither/);
|
||||
});
|
||||
|
||||
it('counts marked fallbacks and unmarked English copies per locale and file', () => {
|
||||
expect(countUntranslated(ROOT)).toEqual({ de: { 'a.ts': { marked: 1, identical: 2 } } });
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user