I have an Akeneo 2.3 running with 10 locales. 1 of the locales is our customised one called ab_AB.
When viewing the category tree in Settings -> Categories
UI or when assigning product to categories UI, the category's label is displayed according to the locale of the logged-in user.
I would like to display the category's label value from ab_AB locale instead of the logged-in user's locale.
I have looked into /vendor/akeneo/pim-community-dev/src/Pim/Bundle/EnrichBundle/Resources/views/CategoryTree
for hints of what to extend/override but not quite sure what to make of it.
To sum up what happens: the tree is generated by calling CategoryTreeController::childrenAction. The rendered twig view will format the categories using the Twig function children_response
, defined in the CategoryExtension.
To set your own locale, you need to override this extension in your project (extend the class and redefine the class parameter pim_enrich.twig.category_extension.class
) and override the protected method getLabel as follows:
protected function getLabel(
CategoryInterface $category,
$withCount = false,
$includeSub = false,
$relatedEntity = 'product'
) {
$category->setLocale('ab_AB');
return parent::getLabel($category, $withCount, $includeSub, $relatedEntity);
}
I successfully tested it with locale fr_FR
while my PIM was in English. Category labels were then in French, both in the Settings → Categories
menu and the category filter of the product grid.