Magento Multilingual Category URL Translation Issue
Hello Magento developers! Today we’re going to tackle an issue that frustrates many of us working on multilingual e-commerce sites - the problem of category names not being translated properly in URLs when using the language switcher.
Pietro has raised a valid concern here. He’s set up two store views for Italian and English, with different category names like ‘Apparel’ (EN) and ‘Abbigliamento’ (IT). However, when switching languages through the site’s language switcher, Magento is directing users to URLs that do not reflect the translated category name.
Let me break down this issue step-by-step:
Understanding the Cause
The core problem lies within how Magento handles URL rewrites for multilingual sites. By default, it creates separate URL keys for each store view. So while your category has a translation (‘Abbigliamento’ in Italian), the URL key remains the same across views.
This is why you’re seeing /en/abbigliamento instead of the expected /en/apparel. Magento isn’t recognizing that ‘Apparel’ and ‘Abbigliamento’ are translations of the same entity; it treats them as separate categories with the same URL key.
The Magento 2 Solution
Luckily, Magento 2 introduced a better handling for multilingual URLs. It allows you to create global URL keys that will be used across all store views. This is exactly what we need in this case.
Here’s how to set it up:
-
Create translations for your category names: Ensure that your categories have proper translations in both languages. You can manage this from the “CMS > Pages” section in the admin panel.
-
Set global URL keys: For each category, you need to define a ‘URL Key’ under the ‘SEO’ meta tag settings. This key will be used across all store views. So for your ‘Apparel’ and ‘Abbigliamento’ categories, they should share the same URL key (e.g.,
apparel). -
Flush Magento cache: After setting these global keys, you need to flush Magento’s cache from the admin panel under “System > Cache Management” for changes to take effect.
Verifying the Fix
Once everything is set up correctly:
- Visit your Italian language store.
- Navigate to your ‘Abbigliamento’ category page.
- Click on the language switcher and select English.
If all goes well, you should be redirected to mystore.com/en/apparel instead of getting a 404 error or being directed to an incorrect URL with the Italian translation.
Conclusion
Remember, properly setting up multilingual URLs in Magento requires careful attention to detail. Always ensure that your categories have translations and that you’ve defined global URL keys for each entity across all store views.
This approach ensures consistent and accurate redirection when users switch languages using the site’s language switcher or other built-in Magento features like the switch HTTP parameter.
Don’t forget, if you need more detailed assistance with your Magento setup or want to learn about advanced SEO techniques, feel free to explore our Magento SEO guide at Laravel Company. We provide in-depth tutorials and best practices for optimizing your e-commerce site.
Happy coding!