SAPUI5中的语言切换

编程入门 行业动态 更新时间:2024-10-26 11:13:42
本文介绍了SAPUI5中的语言切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的 SAPUI5 控件有语言问题.

I've got a language problem with my SAPUI5 controls.

如果我执行例如:

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

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

My i18n files are loaded correctly and all labels are translated to German. But the controls are still in English.

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

The only way to get German controls is with the url parameter:

sap-ui-language=DE

但是在我的情况下我不能使用参数.有什么想法吗?

But I can't use a parameter in my case. Any idea?

推荐答案

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

框架不保证已经创建的、依赖于语言的对象会被这个调用更新.因此,应用程序尽早切换语言仍然是最佳实践,例如在创建任何语言相关对象之前.需要支持更多动态语言更改的应用程序应侦听 localizationChanged 事件并调整它们使用的所有语言相关对象(例如,通过重建其 UI).

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 的回答(但我不允许投票).

Besides that, I fully support Nabi's answer (but I'm not allowed to vote it up).

我只想补充一点,控件(如 FilterBar)最好使用钩子方法:

I just would like to add that controls (like FilterBar) better should use the hook approach:

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

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

Using the hook in controls avoids the need for adding attach + detach calls in init / exit and keeps the event registry small.

更多推荐

SAPUI5中的语言切换

本文发布于:2023-11-22 09:51:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1616953.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语言

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!