Forum

Thread tagged as: Question, Problem

Multi-lingual categories

Hi there,

I face issues when trying to create multi-lingual categories. For info, I've followed the solution 2 of the useful ressource from the docs.

In my template, I'm trying to pass the current language to the <perch:categories> id and set to load a given set of localised categories based on the current language.

This does not work:

<perch:categories id="Country-<perch:content id="current-language" />" label="Country" set="country-<perch:content id="current-language" />" required="true">
       <perch:category id="catTitle" />
</perch:categories>

As an alternative, I've tried to use <perch:if> to display the categories in the template based on the current language. It does work – in the sense that the categories are properly filtered in the admin – but it also outputs two dropdowns in the content manager, one per language.

<perch:if id="current-language" match="eq" value="en">
       <perch:categories id="Country-en" label="Country" set="country-en" required="true">
              <perch:category id="catTitle" />
       </perch:categories>
<perch:else />
       <perch:categories id="Country-fr" label="Country" set="country-fr" required="true">
              <perch:category id="catTitle" />
       </perch:categories>
</perch:if>

Am I doing something wrong?

Cheers, Robin

Robin Pick

Robin Pick 5 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

How are your categories set up?

I've followed the portfolio with categories setup. I have multiple set of categories in the admin, among which Country-fr and Country-en.

The implementation was working perfectly fine before, I started facing the issues above after trying to implement the muli-lingual categories.

Is there any specific detail you need?

Drew McLellan

Drew McLellan 2638 points
Perch Support

So you have different category sets for each language? Are items categorised differently depending on language?

Why not add the translations as fields on the category?

Thanks for the input. Adding the translations as field on the category is ideal indeed.

After adding two fields in the template, I use <perch:if> to decide which translated text to show. This does work:

<perch:if id="current-language" match="eq" value="fr">
       <perch:categories id="Country" label="Country" set="country" required="true">
              <perch:category id="catTitle-fr" />
       </perch:categories>
<perch:else />
       <perch:categories id="Country" label="Country" set="country" required="true">
              <perch:category id="catTitle" />
       </perch:categories>
</perch:if>

One thing I wonder though: it seems I can't use <perch:content id="myLangVar" /> inside the <perch:cateogory>. By using this, I could avoid the use of <perch:if>.

<perch:categories id="Country" label="Country" set="country" required="true">
      <perch:category id="catTitle-<perch:content id="current-language" />" />
</perch:categories>

Any alternative possible?

Cheers & thanks, Robin

Drew McLellan

Drew McLellan 2638 points
Perch Support

You should be able to add scope-parent="true" on the categories tag, and then use it as parent.current-language - although you may have trouble with at illegal dash.