docs

Identifying the Language Code / Locale

For the identification of languages, the framework uses a language code of type string.

The language can be set via the language parameter as described in Available Configuration Options.

Note:

If you need to provide the language as a parameter, we recommend using the sap-ui-language parameter.

Besides sap-ui-language, also the sap-locale and sap-language parameters exist, which should only be used in the context of ABAP-based SAP application servers.

These OpenUI5 configuration options accept the following formats:


Current Language Code / Locale

Note:

The lang attribute for the current language is set at page level for the entire page. If a page contains text that is not in the current language (for example, French elements on an English page), this text cannot be labeled with a different language tag. OpenUI5 doesn’t offer dedicated support to mark application parts, sections, etc. that are in a different language.

Depending on the use case, application developers can alternatively use techniques like directly defining the HTML with the sap.ui.core.HTML control and set the lang attribute accordingly. Another alternative could be iFrame isolation.

OpenUI5 has the notion of a current language. It is determined during the OpenUI5 bootstrap from the following sources of information. The sources are ordered increasingly by priority and the last available user language/locale wins:

  1. Hard-coded OpenUI5 default locale en

  2. Browser-derived language

  3. sap-ui-language configuration parameter (consider the order of the Available Configuration Options)

  4. sap-language configuration parameter (consider the order of the Available Configuration Options)

  5. sap-locale configuration parameter (consider the order of the Available Configuration Options)

  6. Locale configured in the application coding (for more information, see API Reference: sap/base/i18n/Localization.setLanguage. )

        sap.ui.require(["sap/base/i18n/Localization"], (Localization) => {
            // Change the language using the API
            Localization.setLanguage(...);
        		
            // Retrieve the current language
            const sLanguage = Localization.getLanguage();
        });
    

Note:

A call to the Localization.setLanguage. method does not guarantee that all already existing translatable texts will be adapted.

The syntax of the value returned from getLanguage depends on the syntax used for configuration. If the information source is one of the browser language properties, the returned language most likely is in BCP-47 format. If it is configured as a URL parameter, the user might have chosen the JDK-locale syntax.