我的 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中的语言切换
发布评论