cancel
Showing results for 
Search instead for 
Did you mean: 

Getting Selected Language inside UI5 App

mahesh_z
Participant

Hi All,

I have developed an SAPUI5 application which can be used in multiple languages. I have used resourcemodel for this. I have configured this app on my Fiori Launchpad. Now , when I login to my Fiori Launchpad , I need to get the language i selected from the Login screen so that I can select the properties file accordingly. I tried using following code however its not working.

  var urlQueryParameters = window.location.search;

  var selecteLanguage = urlQueryParameters.substring(urlQueryParameters.length - 2, urlQueryParameters.length);

  var bundleURLFile = "";

  switch (selecteLanguage) {

  case "EN":

  bundleURLFile = "i18n/en_EN.properties";

  gSelectedLang = "EN";

  break;

  case "en":

  bundleURLFile = "i18n/en_EN.properties";

  gSelectedLang = "EN";

  break;

  case "FR":

  bundleURLFile = "i18n/fr_FR.properties";

  gSelectedLang = "FR";

  break;

  case "fr":

  bundleURLFile = "i18n/fr_FR.properties";

  gSelectedLang = "FR";

  break;

  default:

  bundleURLFile = "i18n/fr_FR.properties";

  gSelectedLang = "FR";

  break;

  }

  // Setting the Resource Model

  var i18nModel = new sap.ui.model.resource.ResourceModel({

  bundleUrl: bundleURLFile

  });

  sap.ui.getCore().setModel(i18nModel, "i18n");

Keeping above code inside onInit and onAfterRendering method however urlQueryParameters coming as blank, when my entire view is rendered properly and then if I check this , then I am getting "sap-client=060&sap-language=EN".

Please let me know how I can get the selected language from the Login screen of Fiori.

Thanks & Regards,

Mahesh Zeple.

Accepted Solutions (0)

Answers (2)

Answers (2)

santhu_gowdaz
Active Contributor

var sCurrentLocale = sap.ui.getCore().getConfiguration().getLanguage();

Identifying the Language Code / Locale - User Interface Add-On for SAP NetWeaver - SAP Library

mahesh_z
Participant
0 Kudos

Hello Santosh,

Thanks for your reply , i tried the same and outcome is as follows.

When I am on Launchpad by selecting language EN and if it execute sap.ui.getCore().getConfiguration().getLanguage(); i get 'en' which is right however when i clink on my application tile, and go inside my onInit method where debugger is placed, if i again execute this , its giving me 'fr-FR' , ideally it should be 'en' only.

When My view gets rendered, after that if i execute this in console , then its giving me 'en' again.

Is there any language setting we do at backend for Launchpad. I think as our client server is from France , its configured as fr-FR.

Do let me know on this.

Thanks & Regards,

Mahesh Zeple.

santhu_gowdaz
Active Contributor
0 Kudos

May be you are right. I'm not able to help you in this(I'm not using Tiles before). But i'm using EP, If i run my UI5 Application from ABAP server its takes configaration from SAP system. Once i create iView and access from Portal it's takes configaration from Portal.So in your case also it may applicable.

Former Member
0 Kudos

Any solution?

I'm struggling with the same system behaviour.