Search code examples
sapui5

Can't change an app localization during the lifetime


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.


Solution

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