gpt4 book ai didi

javascript - SAPUI5 中的语言切换

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:00:23 24 4
gpt4 key购买 nike

我的 SAPUI5 控件存在语言问题。

如果我执行例如:

sap.ui.getCore().getConfiguration().setLanguage("de");

我的 i18n 文件已正确加载,所有标签都已翻译成德语。但是控件仍然是英文的。

获取德语控件的唯一方法是使用 URL 参数:

sap-ui-language=DE

但是我不能在我的例子中使用参数。有什么想法吗?

最佳答案

请注意sap.ui.getCore().setLanguage()明确指出

The framework does not guarantee that already created, language dependent objects will be updated by this call. It therefore remains best practice for applications to switch the language early, e.g. before any language dependent objects are created. Applications that need to support more dynamic changes of the language should listen to the localizationChanged event and adapt all language dependent objects that they use (e.g. by rebuilding their UI).

除此之外,我完全支持 Nabi 的回答(但我不能投赞成票)。

我只是想添加控件(如 FilterBar)最好使用 Hook 方法:

FilterBar.prototype.onlocalizationChanged = function(oEvent) {
// .. same bundle update code as in Nabi's proposal
}

在控件中使用 Hook 避免了在 init/exit 中添加 attach + detach 调用的需要,并使事件注册表保持较小。

关于javascript - SAPUI5 中的语言切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41039588/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com