Skip to content

Commit 1c008fe

Browse files
committed
fix(cli): i18n coverage counts a blank inline entry the renderer shows as a gap
Empty entries are judged after the shared resolver picks, so a blank zh-TW beside zh-CN is a gap for a zh-Hant reader rather than covered by zh-CN. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibxSGAjHBvjATmenUGp
1 parent c4b41a1 commit 1c008fe

3 files changed

Lines changed: 39 additions & 11 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/cli': patch
3+
---
4+
5+
fix(cli): i18n coverage reports a blank inline-label entry the renderer shows as a gap
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
An inline locale map with an empty entry that the renderer reaches for a locale no longer counts that locale as translated. `{ 'zh-CN': '成员', 'zh-TW': '' }` was reported covered for `zh-Hant` by the Simplified text, while the console shows the blank Traditional entry; it is now a `missing translation` finding, as an empty bundle value already is. Readers that never reach the blank entry are covered as before.

‎packages/cli/src/utils/i18n-coverage.ts‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -545,27 +545,28 @@ function collectExpectedKeys(config: any): ExpectedKey[] {
545545
*
546546
* Empty values do not count, matching {@link lookupKey}'s rule on the bundle
547547
* side — an empty translation is not a translation, whichever side it is
548-
* written on.
548+
* written on. They are judged AFTER the resolver has picked, not before: the
549+
* renderer shows an empty entry when it is the one its limbs reach, so a blank
550+
* `zh-TW` beside `zh-CN` leaves a `zh-Hant` reader looking at nothing, and a
551+
* blank exact `zh-CN` beside `zh` leaves a `zh-CN` reader the same. Dropping
552+
* empties first would let the other entry stand in and report that reader
553+
* covered (#31074).
549554
*/
550555
export function inlineLocaleText(
551556
map: Readonly<Record<string, string>> | undefined,
552557
locale: string,
553558
): string | undefined {
554559
if (!map) return undefined;
555-
const read = (tag: string): string | undefined => {
556-
if (!Object.prototype.hasOwnProperty.call(map, tag)) return undefined;
557-
const value = map[tag];
558-
return typeof value === 'string' && value.length > 0 ? value : undefined;
559-
};
560560
const tag = (locale || 'en').trim();
561561
const base = tag.split('-')[0];
562562
const sameLanguage: Record<string, string> = {};
563563
for (const key of Object.keys(map)) {
564-
const value = read(key);
565-
if (value !== undefined && key.split('-')[0] === base) sameLanguage[key] = value;
564+
const value = map[key];
565+
if (typeof value === 'string' && key.split('-')[0] === base) sameLanguage[key] = value;
566566
}
567567
if (Object.keys(sameLanguage).length === 0) return undefined;
568-
return resolveI18nLabel(sameLanguage, tag);
568+
const shown = resolveI18nLabel(sameLanguage, tag);
569+
return shown !== undefined && shown.length > 0 ? shown : undefined;
569570
}
570571

571572
/**

‎packages/cli/test/i18n-inline-locale-map-coverage.test.ts‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ describe('coverage reads the map the way the renderer does', () => {
277277
{ en: 'Members', 'zh-CN': '成员', 'zh-TW': '成員' },
278278
{ en: 'Members', 'zh-TW': '成員', 'zh-CN': '成员' },
279279
{ en: 'Members', zh: '成员', 'zh-Hant': '成員' },
280+
// An empty entry the renderer reaches (#31074): that reader sees nothing.
281+
{ en: 'Members', 'zh-CN': '成员', 'zh-TW': '' },
282+
{ en: 'Members', zh: '成员', 'zh-CN': '' },
280283
];
281284
const locales = ['en', 'zh', 'zh-CN', 'zh-TW', 'zh-Hans', 'zh-Hant', 'zh-HK', 'ja-JP', 'es-ES'];
282285

@@ -309,7 +312,21 @@ describe('coverage reads the map the way the renderer does', () => {
309312
it("a map with both Chinese scripts covers each reader with its own script's entry (#30910)", () => {
310313
expect(inlineLocaleText({ 'zh-CN': '成员', 'zh-TW': '成員' }, 'zh-Hant')).toBe('成員');
311314
expect(inlineLocaleText({ 'zh-TW': '成員', 'zh-CN': '成员' }, 'zh')).toBe('成员');
312-
// An empty entry of the reader's script is no translation: the other script still covers.
313-
expect(inlineLocaleText({ 'zh-CN': '成员', 'zh-TW': '' }, 'zh-Hant')).toBe('成员');
315+
// (The row that pinned an empty `zh-TW` as covered by `zh-CN` at `zh-Hant`
316+
// moved to the #31074 case below: the renderer shows the empty entry.)
317+
});
318+
319+
it('an empty entry the renderer shows is a gap, not covered by another entry (#31074)', () => {
320+
// Own script: the reader of the Traditional script sees the blank `zh-TW`.
321+
expect(resolveI18nLabel({ 'zh-CN': '成员', 'zh-TW': '' }, 'zh-Hant')).toBe('');
322+
expect(inlineLocaleText({ 'zh-CN': '成员', 'zh-TW': '' }, 'zh-Hant')).toBeUndefined();
323+
expect(inlineLocaleText({ 'zh-CN': '成员', 'zh-TW': '' }, 'zh-HK')).toBeUndefined();
324+
// Own tag: an exact blank `zh-CN` shadows the bare `zh`.
325+
expect(resolveI18nLabel({ zh: '成员', 'zh-CN': '' }, 'zh-CN')).toBe('');
326+
expect(inlineLocaleText({ zh: '成员', 'zh-CN': '' }, 'zh-CN')).toBeUndefined();
327+
// CONTROL: the readers that never reach the blank entry stay covered.
328+
expect(inlineLocaleText({ 'zh-CN': '成员', 'zh-TW': '' }, 'zh-Hans')).toBe('成员');
329+
expect(inlineLocaleText({ zh: '成员', 'zh-CN': '' }, 'zh')).toBe('成员');
330+
expect(inlineLocaleText({ 'zh-CN': '成员' }, 'zh-TW')).toBe('成员');
314331
});
315332
});

0 commit comments

Comments
 (0)