Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: i18n decorator property definition #10521

Merged
merged 3 commits into from
Jan 15, 2025
Merged

fix: i18n decorator property definition #10521

merged 3 commits into from
Jan 15, 2025

Conversation

nnaydenow
Copy link
Contributor

@nnaydenow nnaydenow commented Jan 10, 2025

Problem:
The i18n bundle is stored as a static property in the child class where the i18n decorator is last used. This creates an issue when trying to access the static property from a parent class if it is overridden in the child class. The result might be undefined because the bundle is only stored in the class where the decorator was last used.

This issue can be observed on the https://sap.github.io/ui5-webcomponents/nightly/components/Tree/
Note: The issue is reproducible only if the ui5-tree and ui5-tree-item components are loaded. For local testing, the defined components in the bundle should be limited to just these two.

Example:

abstract class ListItem extends ListItemBase {
	@i18n("@ui5/webcomponents")
	static i18nBundle: I18nBundle;

	get _accInfo(): AccInfo {
		return {
			ariaLabel: ListItem.i18nBundle.getText(ARIA_LABEL_LIST_ITEM_CHECKBOX) // This ListItem.i18nBundle is undefined because the bundle is only registered in TreeItemBase.
		};
	}
}

class TreeItemBase extends ListItem {
	@i18n("@ui5/webcomponents")
	static i18nBundle: I18nBundle;
}

Solution:
The loaded bundle is now stored in a bundle storage variable. A getter is defined for each property that stores a bundle in every class where i18n decorator is used. This ensures access to the bundle storage for every class where the i18n decorator is used.

@nnaydenow nnaydenow requested a review from vladitasev January 10, 2025 16:10
@nnaydenow nnaydenow merged commit d19f4e9 into main Jan 15, 2025
10 checks passed
@nnaydenow nnaydenow deleted the i18n-dec branch January 15, 2025 08:42
@ui5-webcomponents-bot
Copy link
Collaborator

🎉 This PR is included in version v2.7.0-rc.0 🎉

The release is available on v2.7.0-rc.0

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants