cancel
Showing results for 
Search instead for 
Did you mean: 

Backoffice: Change the order of locales on localized attributes

janbu
Explorer
783

We are using a bunch of locales in our SAP Commerce instance. After updating to 20.05, our previous customization of changing the ordering not really works anymore, the localized values are now in random order (or at least I don't see any pattern):

Previously, it was possible to override the BackofficeLocaleService and rearrange the locales according to our needs. But now this method is used to get the locales, but the ordering is ignored. Is there any possiblility to change the order of the languages in the localized editor?

oscarerenas
Discoverer
0 Kudos

Hi, Jan

I have the same issue, did you find a solution?

Thank you.

janbu
Explorer
0 Kudos

Not yet...

franziskah
Discoverer
0 Kudos

Hello,

we have the same problem, has anyone found a solution?

janbu
Explorer
0 Kudos

We tried to contact SAP Support, but got no luck and according to the SAP Support we should contact an SAP consultant to implement a custom implementation...

Let me know if you find a workaround or a solution!

0 Kudos

Hello, we also have the same problem. After switching from 1811 to 2105 the ordering of localizedAttributes switched to "random". Only the LanguageSelection-Widget on top-right seems to be ordered by Language-Label.

previously: All lists were consistently sorted by the locale-keys like "de". Only the current-Locale moved on top.

Now: Even in the Backoffice itself (Locales-Selection top-right; Multi-Lang-Attribute; Bulk ex/imports), the ordering is not consistent anymore.

It seems like the sequence isn't fixed anymore due to internal handling with maps/sets and missing sorting before rendering.

Let us know if there is a solution or anyone get a workaround!

View Entire Topic
kielboatmandf
Discoverer
0 Kudos

you need to extend com.hybris.cockpitng.editor.localized.LocalizedEditor and then in your custom editor you have to override getReadableLocales and getWriteableLocales methods

These method, in standard code, use HashSet which does not guarantee order.  When you override them you have to, for the retained locales, sort them and then collect them into a Set implementation that retains order e.g LinkedHashSet

 

@Override
	protected Set<Locale> getReadableLocales(final EditorContext editorContext)
	{
		return getLocales(editorContext.getReadableLocales());
	}

	@Override
	protected Set<Locale> getWriteableLocales(final EditorContext editorContext)
	{
		return getLocales(editorContext.getWritableLocales());
	}

	private Set<Locale> getLocales(final Set<Locale> contextValue)
	{
		final Set<Locale> locales = Optional.ofNullable(contextValue)
			.map(Sets::newHashSet)
			.orElseGet(Sets::newHashSet);
		final List<Locale> enabledDataLocales = getCockpitLocaleService().getEnabledDataLocales(getCockpitUserService().getCurrentUser());
		locales.retainAll(enabledDataLocales);
		return locales.stream()
			// Sort & Use LinkedHashSet to retain order
			// the call to this then ensures the session locale is rendered first
			// followed by all other locales, based on the order of the set
			.sorted(Comparator.comparing(Locale::toString))
			.collect(Collectors.toCollection(LinkedHashSet::new));
	}

 

 

After this you then need to create the definition.xml for your custom editor (basically copy the standard LocalizedEditor definition - below - and tweak it with your custom package and class name)

 

<?xml version="1.0" encoding="UTF-8"?>
<!--
 Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved
-->
<editor-definition id="com.hybris.cockpitng.editor.localized" << change the id
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:noNamespaceSchemaLocation="http://www.hybris.com/schema/cockpitng/editor-definition.xsd">

	<name>Localized Editor</name>
	<description>Localized Editor</description>
	<author>hybris</author> << change
	<version>0.1</version>
	<type>^Localized\((.*)\)$</type>
	<editorClassName>com.hybris.cockpitng.editor.localized.LocalizedEditor</editorClassName> << change
	<handlesLocalization>true</handlesLocalization>
</editor-definition>

 

then you have to register the editor (in backoffice spring file) as the default editor, so it overrides the standard one

 

	<alias name="coreBackofficeEditorRegistry" alias="editorRegistry"/>
	<bean id="coreBackofficeEditorRegistry" parent="simpleEditorRegistry">
		<property name="defaultEditorMapping">
			<map merge="true" key-type="java.lang.String" value-type="java.lang.String">
				<entry key="^Localized\((.*)\)$" value=" TOUR CLASSNAME / EDITOR ID"/>
			</map>
		</property>
	</bean>

 

Screenshot 2024-09-13 at 14.28.50.png