on ‎2018 Nov 02 4:10 PM
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
Request clarification before answering.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.

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.
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.

You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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;
}
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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>

You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The Language type has an active attribute. For a specific Language item, you can set it to false.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
| User | Count |
|---|---|
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.