cancel
Showing results for 
Search instead for 
Did you mean: 

How to override the selected language behavior on product cockpit login?

amitpanwar
Advisor
Advisor
0 Kudos

I would like to override the selected language behavior for the product cockpit labels based on the following use case:

  • If the selected language on login screen is assigned to any of the user's readable catalogs. Use the selected language.

  • otherwise,
    • if a session language is assigned to user's profile use the user's session language.

    • otherwise use ENGLISH (en)

I have overridden the DefaultCockpitUserDetailsService.loadUserByUsername as:

 private String getLoginLanguage(String loginLanguage, final String userUid)
     {
         boolean languageAvailableInCatalog = false;
         final Collection<CatalogVersionModel> catalogVersions = catalogVersionService.getAllCatalogVersions();
         for (final CatalogVersionModel catalogVersion : catalogVersions)
         {
             if (catalogVersion.getCatalog().getId().equals("Default"))
             {
                 continue;
             }
             for (final LanguageModel language : catalogVersion.getLanguages())
             {
                 if (StringUtils.equalsIgnoreCase(language.getIsocode(), loginLanguage))
                 {
                     languageAvailableInCatalog = true;
                     break;
                 }
             }
         }
         if (!languageAvailableInCatalog)
         {
             final LanguageModel sessionLanguage = userService.getUserForUID(userUid).getSessionLanguage();
             if (null != sessionLanguage)
             {
                 loginLanguage = sessionLanguage.getIsocode();
             }
             else
             {
                 loginLanguage = Locale.ENGLISH.getLanguage();
             }
         }
         return loginLanguage;
     }
 
 @Override
     public CoreUserDetails loadUserByUsername(final String username)
     {
         final CoreUserDetails coreUserDetails = super.loadUserByUsername(username);
         commonI18NService.setCurrentLanguage(commonI18NService.getLanguage(getLoginLanguage(commonI18NService.getCurrentLanguage().getIsocode(), username)));
         return coreUserDetails;
     }

It reflects in the data values but doesn't reflect in the cockpit labels.

Could any expert help here?

Accepted Solutions (0)

Answers (3)

Answers (3)

laurent-malvert
Product and Topic Expert
Product and Topic Expert
0 Kudos

You want:

 i18NService.setCurrentLocale(/* ... */)

Not:

 commonI18NService.setCurrentLanguage(/* ... */)

amitpanwar
Advisor
Advisor
0 Kudos

I already tried this but this doesn't work either.

amitpanwar
Advisor
Advisor
0 Kudos

Hi Haitao,

Probably, you didn't understand the question. As I mentioned, if the login language is not available in the user's accessible catalog then I need to use other language based on the mentioned use case.

In that case, I need to render the cockpit labels in the language other than the login language.

Regards, Amit

Former Member
0 Kudos

Hi, Amit,

There is one way to set labels in the language selected in the cockpit login page.

  1. Add context to the areas where you want to use. For example, editorArea_myvalue.xml

  2. Create the i3-label.properties and i3-label_de.properties etc for the language you want to display.

  3. Rebuild your codebase

For more details, please refer to:

https://help.hybris.com/6.0.0/hcd/722df5d9d2c843a78dd25d457cb07c8f.html#loio6b6e5c1115db4b8ab74aaa45...

Regards

Haitao