Skip to Content
0
Nov 29, 2022 at 01:30 PM

Accessing and using Language and Regional Settings in Custom UI5 Apps

468 Views Last edit Dec 12, 2022 at 10:48 AM 10 rev

Users have the option to store personal preferences like time format, date format in the Fiori Launchpad. (Maintaining Your Language and Regional Settings)

These settings are stored in the sap table USR01.

In UI5 Applications we can access these informations via

sap.ui.getCore().getConfiguration().getFormatSettings()...

But how do we apply these settings to the app/to the controls in the app... ?

Language is possible via:

sap.ui.getCore().getConfiguration().setLanguage(sLanguage);

But how about formatting Date Formats/Time Formats/... ?

Normally the sap.ui.model.type is used but this model type gives a damn about the user preferences...

Ignoring sap.ui.model.types and using custom formatters also feels wrong....

Is there an offical documentation i missed ?

Thanks in advance

-----EDIT-----

I can get/set these options via:

var sDateFormat = sap.ui.getCore().getConfiguration().getFormatSettings().getDatePattern("medium");
sap.ui.getCore().getConfiguration().getFormatSettings().setDatePattern("medium", sDateFormat);<br>

like Margot Wollny mentioned, but that's not enough for controls to adapt to these settings.

For example the following sap.m.ObjectAttribute doesn't care about these settings... (attachment>UploadedAt contains an JS Date Object)

	<ObjectAttribute title="{i18n>uploadedAt}" text="{ path: 'attachment>UploadedAt', type: 'sap.ui.model.type.DateTime', formatOptions: { style: 'medium'}}" class="sapUiTinyMarginEnd"/><br>

I set these settings before i instantiate the app. (Language(i18n) works fine/formattings not)

What am i missing ?

UI5 Version: 1.90.7

Environment: Fiori Launchpad --> Web UI (WCF) --> thtmlbx:htmlIsland(iframe) --> Custom UI5 App

-- Solution --

The answers of Margot Wollny and Jun Wu are both correct.

Normally nothing needs to be consirdered as a developer. The settings are applied automatically, as Jun Wu mentioned. If your application is running in an different "sap.ui.getCore()" instance (for example an iframe) make sure to correctly transfer these settings.

You can either use

sap.ui.getCore().getConfiguration().getFormatSettings().setLegacyDateFormat("9"); //1-9, A-C
sap.ui.getCore().getConfiguration().getFormatSettings().setDatePattern("short", "dd-MM-YYYY"); //YYYY-dd-MM or sth. else