4444
4545import { deepMerge } from '@objectstack/core' ;
4646import type { TranslationBundle , TranslationData } from '@objectstack/spec/system' ;
47+ import { resolveI18nLabel } from '@objectstack/spec/ui' ;
4748import { collectExpectedEntries , type ExpectedEntry } from './i18n-bundle-extract.js' ;
4849
4950export type CoverageSeverity = 'error' | 'warning' ;
@@ -518,15 +519,16 @@ function collectExpectedKeys(config: any): ExpectedKey[] {
518519 * as covered the moment a map exists, which is the mirror image of the bug
519520 * this function was added to fix: one answer standing for two opposite facts.
520521 *
521- * So only the **tag-matching** limbs count as coverage, in the reference's own
522- * order and with its own case rules:
523- *
524- * 1. the exact tag — `zh-CN` reads the key `zh-CN`;
525- * 2. the base language — `zh-CN` reads the key `zh`;
526- * 3. the first region-qualified sibling sharing that base — `zh` reads
527- * `zh-CN`; `zh-TW` reads `zh-CN` too. Same language, other region: what
528- * the renderer really shows, and a translation into the language asked
529- * for.
522+ * So only the **tag-matching** limbs count as coverage: the entries whose
523+ * language subtag is the locale's (the exact tag, the bare language, a
524+ * region-qualified sibling). Which of them the reader sees is asked of
525+ * `resolveI18nLabel` itself, over the map cut down to those entries, so this
526+ * function keeps no copy of the resolver's limb order: `zh-CN` reads `zh-CN`,
527+ * else `zh`; `zh` reads `zh-CN`; `zh-TW` reads `zh-CN` when the map has no
528+ * Traditional entry, and `zh-TW` over `zh-CN` when it has both (the script
529+ * preference where the platform table splits a language). Same language,
530+ * other region: what the renderer really shows, and a translation into the
531+ * language asked for.
530532 *
531533 * The fallback limbs are excluded because falling back **is** what an
532534 * untranslated locale looks like: a `ja-JP` reader shown the `en` entry is
@@ -536,7 +538,8 @@ function collectExpectedKeys(config: any): ExpectedKey[] {
536538 * `i18n-label-resolver.ts` is the authority on the limb rule and on the case
537539 * asymmetry mirrored here (region case is irrelevant because limb 3 compares
538540 * language subtags only; language case is significant, because the reference
539- * folds neither side). `inline-locale-coverage-parity.test.ts` pins this
541+ * folds neither side). The describe block "coverage reads the map the way the
542+ * renderer does" in `test/i18n-inline-locale-map-coverage.test.ts` pins this
540543 * function against `resolveI18nLabel`: whenever this says "covered", the
541544 * renderer really shows that entry.
542545 *
@@ -555,18 +558,14 @@ export function inlineLocaleText(
555558 return typeof value === 'string' && value . length > 0 ? value : undefined ;
556559 } ;
557560 const tag = ( locale || 'en' ) . trim ( ) ;
558- const exact = read ( tag ) ;
559- if ( exact !== undefined ) return exact ;
560561 const base = tag . split ( '-' ) [ 0 ] ;
561- const baseHit = read ( base ) ;
562- if ( baseHit !== undefined ) return baseHit ;
562+ const sameLanguage : Record < string , string > = { } ;
563563 for ( const key of Object . keys ( map ) ) {
564- if ( key . split ( '-' ) [ 0 ] === base ) {
565- const sibling = read ( key ) ;
566- if ( sibling !== undefined ) return sibling ;
567- }
564+ const value = read ( key ) ;
565+ if ( value !== undefined && key . split ( '-' ) [ 0 ] === base ) sameLanguage [ key ] = value ;
568566 }
569- return undefined ;
567+ if ( Object . keys ( sameLanguage ) . length === 0 ) return undefined ;
568+ return resolveI18nLabel ( sameLanguage , tag ) ;
570569}
571570
572571/**
0 commit comments