Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Language switch in SAPUI5

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

If I execute e.g.:

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

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

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?

like image 831
alexP Avatar asked Feb 05 '23 13:02

alexP


1 Answers

Please note that sap.ui.getCore().setLanguage() explicitly states

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).

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

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
}

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

like image 198
codeworrior Avatar answered Feb 08 '23 04:02

codeworrior