1

As far as I know, UI5 determines the wanted localization based on browser's HTTP header accept-language with respect of supportedLocales and fallbackLocale values of the manifest.json app descriptor.

In my case, however, initially user sees an authorization dialog in English and after authorization I would like set an app localization based on a user config, loaded upon successful authorization.

Based on Language switch in SAPUI5, I've tried to apply:

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

in the view onInit() but instead I get a blinked view in the desired localization and then an empty window.

Since sap.ui.getCore().setLanguage() does not guarantee that already created, language dependent objects will be updated by this call, I've tried location.reload(); to trigger a complete page reloading and rebuilding all UI5 elements but it doesn't help.

Mike
  • 14,010
  • 29
  • 101
  • 161

2 Answers2

2

I'm not sure if this can be done without a reload.

For modern browsers, you can use this code to change the URL:

const oURL = new URL(window.location.href);
window.location.href = oURL.searchParams.set("sap-ui-language", "en").toString();

If, for some reasons, you have the language already in the URL, you need to add a cachebreaker.

Benedikt Kromer
  • 711
  • 6
  • 22
  • Although this approach works, it adds `?sap-ui-language=en` to the URL, which I would like ideally to avoid. In addition to _possible_ issues with caching. – Mike Sep 11 '21 at 09:00
1

My go-to choice is

sap.ui.getCore().getConfiguration().applySettings({
    language: 'de',
});

This switches the used i18n bundle.

However, there are still some occurrences that don't get translated e.g. the work-day labels in a sap.m.PlanningCalendar, which remain in the browser's language.

fmi21
  • 485
  • 3
  • 15