cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Remove languages from Backoffice Login page and from quick toggle widget

imsanjayrawat
Explorer
0 Likes
3,959

Hi All,

There is a customer requirement to remove language from backoffice login page and also from quick toggle widget. As understood from hybris wiki, locales can be disabled by adding context in cockpit-config.xml. It is disabling the language, but not removing languages from the widget.

Is there any way to remove languages from backoffice login and quick toggle widget without removing languages from the internationalization-->remove/disable language or hiding it via UI? Or It is possible by overriding DefaultLocalizationService?

Hybris version: 1808

Thanks in Advance! Regards, Sanjay Singh

Accepted Solutions (1)

Accepted Solutions (1)

arvind-kumar_avinash
Active Contributor

Using the following code, you can restrict the application to only two languages:

 public class CustomLocalizationService extends DefaultLocalizationService{
     @Override
     public Set<Locale> getSupportedDataLocales(){
         final Set<Locale> supportedDataLocales = new HashSet<>();
         supportedDataLocales.add(Locale.ENGLISH);
         supportedDataLocales.add(Locale.GERMAN);
         return supportedDataLocales;
     }
  }

Spring configuration:

 <alias alias="localizationService" name="customLocalizationService" />
 <bean id="customLocalizationService" class="your-package-name.CustomLocalizationService" parent="defaultLocalizationService"/>

If you want to restrict the application to these two languages only for anonymous users (e.g. at the login screen), you can use the following code:

 public class CustomLocalizationService extends DefaultLocalizationService{
     @Resource
     private UserService userService;
     @Override
     public Set<Locale> getSupportedDataLocales(){
         final Set<Locale> supportedDataLocales = new HashSet<>();
         if (userService.isAnonymousUser(userService.getCurrentUser())){
             supportedDataLocales.add(Locale.ENGLISH);
             supportedDataLocales.add(Locale.GERMAN);
         } else {
             supportedDataLocales.addAll(super.getSupportedDataLocales());
         }
         return supportedDataLocales;
     }
  }

At this moment, I do not know the solution how to restrict the languages from Quick Toggle Locale widget. I tried the configuration mentioned at https://help.hybris.com/6.2.0/hcd/8c36a57386691014ba298e76544c6e6a.html but it didn't work. I will update my answer with the solution once I find it.

arvind-kumar_avinash
Active Contributor
0 Likes

I want to share another idea to approach the solution to this problem. I came across https://help.hybris.com/1811/hcd/3c97f2858f0b4ec7b9949a4801612744.html and I think this hints another way to fulfil your requirement. I will update this answer once I get some time to do it myself. Hopefully, you will yourself or someone else will try it and update this page with the result.

Former Member
0 Likes

Hi , I actually suggested this in my initial response https://answers.sap.com/answers/12803750/view.html but unfortunately it seems this is not working as documented, at least in v1808.

arvind-kumar_avinash
Active Contributor
0 Likes

Ah...I missed checking your answer before I posted it. I have converted it as a comment but I will keep it here as the link in it can be helpful to others.

imsanjayrawat
Explorer
0 Likes

Arvind- This change was already in place to boost up the login performance of the backoffice, so instead of loading all languages during login, it is only loading two languages that was defined in the configuration file

Answers (5)

Answers (5)

Former Member
0 Likes

I used the approach suggested by but changed the logic a little bit and was able to accomplish the desired effect both in the login dialog and on language quick toggle. The modifications I did:

  • overiding protected Map getSupportedLocales() method instead of public Set getSupportedDataLocales()

  • introducing a simple logic to retrieve languages that are set to active SELECT {PK} FROM {Language as l} WHERE {l.active} = true

You can compare the original method getSupportedLocales in DefaultLocalizationService for reference.

Former Member
0 Likes

When I played around with the solution I found that actually getSupportedLocales() is also called from storefront, so you might run into troubles if you have a language that is set as active=false but you're using it on storefront. I modified the solution to work and tested both on storefront and backoffice. For reference, please find the code I used for my CustomLocalizationService

  @Override
     public Set<Locale> getSupportedDataLocales() {
         return Collections.unmodifiableSet(getActiveLocales());
     }
 
     private Set<Locale> getActiveLocales() {
         JaloTypeCacheUnit cache = (new JaloTypeCacheUnit(Registry.getCurrentTenant().getCache(), 32, "activeLocales_" + JaloSession.getCurrentSession().getUser().getPK()) {
             public Object compute() {
                 String query = "SELECT {PK} FROM {Language as l} WHERE {l.active} = true";
                 return flexibleSearchService.<LanguageModel>search(query).getResult()
                         .stream().map(language -> new Locale(language.getIsocode())).collect(Collectors.toSet());
             }
         });
         Set<Locale> result = (Set<Locale>)cache.getCached();
         return result;
     }
Former Member
0 Likes

if this works for you, please upvote and accept the answer.

imsanjayrawat
Explorer
0 Likes

Lukasz- i already mentioned in previous comments that language didn't need to marked as inactive as it might be possible that languages are getting used when loading data from PIM system.

imsanjayrawat
Explorer
0 Likes

hi ,

I added below configuration in the extensionname-backoffice-config.xml, however it is not removing the disabled languages from the quick toggle however disable language in the widget, if you see the screen shot you have pasted , it is showing German although you have disabled german in the configurations.

 <al:cockpit-locales xmlns:al="http://www.hybris.com/cockpitng/config/availableLocales">
   <al:cockpit-locale name="english" locale="en-US" enabled="true"/>
   <al:cockpit-locale name="german" locale="de-DE" enabled="true"/>
   <al:cockpit-locale name="french" locale="fr-FR" enabled="false"/>
 </al:cockpit-locales>
  

I have also seen the OOB logincomposser class, it using a common method populatelocale to get locale for showing it on UI and in the application, so only option left is to remove the languages that are not getting used in the e-commerce.

SAP need to provide a better control on showing locales on UI without removing locale from the application.

regards, Sanjay Singh

Former Member
0 Likes

Hi Sanjay, You're right I missed the "German" thing on the screenshot. Polish is missing because I removed the language completely in backoffice.

Former Member
0 Likes

Hi, I was able to hide a language from the quick toggle widget by specifying following widget config (note the enabled="false" for some languages you want to hide). As far as I was able to figure out by inspecting the platform code, for removing an entry from the login screen, you have to delete the language from backoffice completely (that would remove it also from storefront though).

 <context component="available-locales" principal="advanced">
     <al:cockpit-locales xmlns:al="http://www.hybris.com/cockpitng/config/availableLocales">
         <al:cockpit-locale name="english" locale="en-US" enabled="true"/>
         <al:cockpit-locale name="german" locale="de" enabled="false"/>
         <al:cockpit-locale name="polish" locale="pl" enabled="false"/>
     </al:cockpit-locales>
 </context>

geffchang
Active Contributor
0 Likes

The Language type has an active attribute. For a specific Language item, you can set it to false.

Former Member
0 Likes

Hi Geff, unfortunately this setting only affects storefront availability of the language, not the backoffice listing.

imsanjayrawat
Explorer
0 Likes

Hi Geff,

Thanks for your response!

I tried this option but it didn't work and i personally didn't feel to disable the language,as it might be possible that particular locale need to be supported in future whereas not required to show it login screen

regards, Sanjay Singh

Former Member
0 Likes

In our installation on earlier version (6.5) the setting of lang.packs property allowed to limit languages available on hybris login screen. This doesn't impact the languages visible on the storefront. You can set that in your local.properties file and see if that works for you.

imsanjayrawat
Explorer
0 Likes

hi Lukas, Thanks for your response, I already tried this configuration, it didn't help. Is there any other way to achieve it. Regards, Sanjay Singh

Former Member
0 Likes

Note that restricting the languages via the "lang.packs" property makes some of the ootb ImpEx files fail (at least in CX Commerce 1811), since some ImpEx files blindly reference languages without checking if they are available.

Run

 find . -name "*.impex" | xargs grep "es_CO,"

in your Hybris installation to find examples.