@@ -3034,7 +3034,23 @@ export async function pairTranslationBundleOf(
30343034 } catch {
30353035 return undefined ;
30363036 }
3037- if ( typeof base !== 'string' || base === '' ) return undefined ;
3037+ return pairTranslationBundleOfBase ( p , base , memo ) ;
3038+ }
3039+
3040+ /**
3041+ * `getPairTranslationBundle(base)` on `protocol`, read once per base through
3042+ * `memo` — {@link pairTranslationBundleOf}'s second question, also asked by
3043+ * {@link withoutStaleObjectPlural} for the base an object's owner ships in.
3044+ * `undefined` on every uncertainty, {@link pairTranslationBundleOf}'s rule.
3045+ */
3046+ function pairTranslationBundleOfBase (
3047+ protocol : unknown ,
3048+ base : unknown ,
3049+ memo ?: Map < string , Promise < unknown > > ,
3050+ ) : Promise < unknown > {
3051+ const p : any = protocol ;
3052+ if ( typeof base !== 'string' || base === '' ) return Promise . resolve ( undefined ) ;
3053+ if ( ! p || typeof p . getPairTranslationBundle !== 'function' ) return Promise . resolve ( undefined ) ;
30383054 let pending = memo ?. get ( base ) ;
30393055 if ( pending === undefined ) {
30403056 pending = Promise . resolve ( )
@@ -3045,6 +3061,66 @@ export async function pairTranslationBundleOf(
30453061 return pending ;
30463062}
30473063
3064+ /** A non-empty string, or `undefined`. */
3065+ function nonEmptyText ( value : unknown ) : string | undefined {
3066+ return typeof value === 'string' && value . length > 0 ? value : undefined ;
3067+ }
3068+
3069+ /**
3070+ * [#30391] `translated` — what the object translator answered for the served
3071+ * object `input` — without a plural the catalog made up for a renamed object.
3072+ *
3073+ * An object extension that renames `label` and declares no `pluralLabel` is
3074+ * served without one (the fold takes the plural of the old label off,
3075+ * `mergeObjectDefinitions` in `@objectstack/objectql`). The translator answers
3076+ * a missing `pluralLabel` with the catalog's `objects.NAME.pluralLabel`, and
3077+ * that entry is the base package's translation of the plural the extension
3078+ * left behind: it names the old label. So where `input` carries no plural, the
3079+ * packaged base declares one, and `input`'s `label` diverged from the packaged
3080+ * one, the catalog's plural is not served. In its place, the ruled order
3081+ * (ruling record 6631250894: a translation in the pair, then the override's
3082+ * own text, then the base's translation): the base's pair's own translation of
3083+ * the plural when it ships one, read through the same translator over the
3084+ * pair's bundle alone; otherwise what `input` carries, which is no plural —
3085+ * what an object that declares no `pluralLabel` is served.
3086+ *
3087+ * An object served WITH a plural (an extension that sets one, a tenant rename
3088+ * that kept one) and an object whose label is the packaged one are served
3089+ * unchanged, as is every object with no packaged base. Returns `translated`
3090+ * itself when nothing changes; the pair is read only when the rule applies.
3091+ */
3092+ async function withoutStaleObjectPlural (
3093+ protocol : unknown ,
3094+ input : Record < string , unknown > ,
3095+ translated : Record < string , unknown > ,
3096+ packagedBase : unknown ,
3097+ translateOptions : Record < string , unknown > ,
3098+ memo ?: Map < string , Promise < unknown > > ,
3099+ ) : Promise < Record < string , unknown > > {
3100+ if ( nonEmptyText ( input . pluralLabel ) !== undefined ) return translated ;
3101+ const packaged = packagedBase && typeof packagedBase === 'object' ? packagedBase as Record < string , unknown > : undefined ;
3102+ if ( ! packaged || nonEmptyText ( packaged . pluralLabel ) === undefined ) return translated ;
3103+ const label = nonEmptyText ( input . label ) ;
3104+ if ( label === undefined || label === packaged . label ) return translated ;
3105+ const pairBundle = await pairTranslationBundleOfBase ( protocol , packaged . _packageId , memo ) ;
3106+ let pairPlural : string | undefined ;
3107+ if ( pairBundle !== undefined && typeof input . name === 'string' ) {
3108+ const { translateMetadataDocument } = await import ( '@objectstack/spec/system' ) ;
3109+ const read = translateMetadataDocument ( 'object' , { name : input . name } as any , pairBundle as any , translateOptions as any ) ;
3110+ pairPlural = nonEmptyText ( ( read as Record < string , unknown > | undefined ) ?. pluralLabel ) ;
3111+ }
3112+ if ( pairPlural !== undefined ) {
3113+ return translated . pluralLabel === pairPlural ? translated : { ...translated , pluralLabel : pairPlural } ;
3114+ }
3115+ if ( ! ( 'pluralLabel' in input ) ) {
3116+ if ( ! ( 'pluralLabel' in translated ) ) return translated ;
3117+ const served : Record < string , unknown > = { ...translated } ;
3118+ delete served . pluralLabel ;
3119+ return served ;
3120+ }
3121+ return translated . pluralLabel === input . pluralLabel ? translated : { ...translated , pluralLabel : input . pluralLabel } ;
3122+ }
3123+
30483124/** How a transport reaches what the list translation reads. */
30493125export interface MetaListTranslationSources {
30503126 /** This request's i18n service, or `undefined` when the deployment has none. */
@@ -3110,12 +3186,19 @@ export async function translateMetaList(
31103186 // OUTER `{ type, items }`), so every element translates directly (#5563).
31113187 const translated = await Promise . all ( arr . map ( async ( item ) => {
31123188 const pairBundle = p === undefined ? undefined : await pairTranslationBundleOf ( p , metaType , item , pairBundles ) ;
3189+ const packagedBase = packagedObjectBaseOf ( p , metaType , item ?. name ) ;
31133190 const out = translateMetadataDocument ( metaType , item , bundle , {
31143191 ...metaTranslateOptions ( i18n , locale ) ,
3115- packagedBase : packagedObjectBaseOf ( p , metaType , item ?. name ) ,
3192+ packagedBase,
31163193 ...( pairBundle !== undefined ? { pairBundle : pairBundle as any } : { } ) ,
31173194 } ) ;
3118- return metaType === 'view' && item && typeof item === 'object' ? withoutInventedViewLabel ( item , out ) : out ;
3195+ if ( ! item || typeof item !== 'object' ) return out ;
3196+ if ( metaType === 'view' ) return withoutInventedViewLabel ( item , out ) ;
3197+ // [#30391] A renamed object's plural, read once per base for the page.
3198+ if ( metaType === 'object' ) {
3199+ return withoutStaleObjectPlural ( p , item , out , packagedBase , metaTranslateOptions ( i18n , locale ) , pairBundles ) ;
3200+ }
3201+ return out ;
31193202 } ) ) ;
31203203 return Array . isArray ( raw ) ? translated : { ...raw , items : translated } ;
31213204}
@@ -3183,7 +3266,15 @@ export async function translateMetaDocument(
31833266 packagedBase,
31843267 ...( pairBundle !== undefined ? { pairBundle : pairBundle as any } : { } ) ,
31853268 } ) ;
3186- return metaType === 'view' ? withoutInventedViewLabel ( document as Record < string , unknown > , translated ) : translated ;
3269+ if ( metaType === 'view' ) return withoutInventedViewLabel ( document as Record < string , unknown > , translated ) ;
3270+ if ( metaType === 'object' && translated && typeof translated === 'object' ) {
3271+ // [#30391] A renamed object's plural.
3272+ return withoutStaleObjectPlural (
3273+ p , document as Record < string , unknown > , translated as Record < string , unknown > , packagedBase ,
3274+ metaTranslateOptions ( i18n , locale ) ,
3275+ ) ;
3276+ }
3277+ return translated ;
31873278}
31883279
31893280/**
0 commit comments