Skip to content

Commit

Permalink
fix: i18n decorator property definition
Browse files Browse the repository at this point in the history
  • Loading branch information
nnaydenow committed Jan 10, 2025
1 parent b79b529 commit af6ae6b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/base/src/UI5Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -1288,6 +1289,11 @@ abstract class UI5Element extends HTMLElement {

static asyncFinished: boolean;
static definePromise: Promise<void> | undefined;
static i18nBundleStorage: Record<string, I18nBundle> = {};

static get i18nBundles(): Record<string, I18nBundle> {
return this.i18nBundleStorage;
}

/**
* Registers a UI5 Web Component in the browser window object
Expand All @@ -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<string, any>)[propertyName] = i18nBundles[index];
this.i18nBundleStorage[propertyName] = i18nBundles[index];
});
this.asyncFinished = true;
};
Expand Down
7 changes: 7 additions & 0 deletions packages/base/src/decorators/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit af6ae6b

Please sign in to comment.