From af6ae6bda49f3edd38f94d49e3c5724841449d7d Mon Sep 17 00:00:00 2001 From: Nayden Naydenov Date: Fri, 10 Jan 2025 17:54:02 +0200 Subject: [PATCH] fix: i18n decorator property definition --- packages/base/src/UI5Element.ts | 9 +++++++-- packages/base/src/decorators/i18n.ts | 7 +++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/base/src/UI5Element.ts b/packages/base/src/UI5Element.ts index 283cf8b2d042..3673ba07c435 100644 --- a/packages/base/src/UI5Element.ts +++ b/packages/base/src/UI5Element.ts @@ -41,6 +41,7 @@ import { updateFormValue, setFormValue } from "./features/InputElementsFormSuppo import type { IFormInputElement } from "./features/InputElementsFormSupport.js"; import { getComponentFeature, subscribeForFeatureLoad } from "./FeaturesRegistry.js"; import { getI18nBundle } from "./i18nBundle.js"; +import type I18nBundle from "./i18nBundle.js"; import { fetchCldr } from "./asset-registries/LocaleData.js"; import getLocale from "./locale/getLocale.js"; @@ -1288,6 +1289,11 @@ abstract class UI5Element extends HTMLElement { static asyncFinished: boolean; static definePromise: Promise | undefined; + static i18nBundleStorage: Record = {}; + + static get i18nBundles(): Record { + return this.i18nBundleStorage; + } /** * Registers a UI5 Web Component in the browser window object @@ -1304,8 +1310,7 @@ abstract class UI5Element extends HTMLElement { const [i18nBundles] = result; Object.entries(this.getMetadata().getI18n()).forEach((pair, index) => { const propertyName = pair[0]; - const targetClass = pair[1].target; - (targetClass as Record)[propertyName] = i18nBundles[index]; + this.i18nBundleStorage[propertyName] = i18nBundles[index]; }); this.asyncFinished = true; }; diff --git a/packages/base/src/decorators/i18n.ts b/packages/base/src/decorators/i18n.ts index 7b2858ba9d46..1b2de8e9e40c 100644 --- a/packages/base/src/decorators/i18n.ts +++ b/packages/base/src/decorators/i18n.ts @@ -20,6 +20,13 @@ const i18n = (bundleName: string): i18nDecorator => { if (!target.metadata.i18n) { target.metadata.i18n = {}; } + + Object.defineProperty(target, propertyName, { + get() { + return target.i18nBundles[propertyName]; + }, + }); + target.metadata.i18n[propertyName] = { bundleName, target,