How to Translate Using XML in Magento 2
It is a general observation that customers prefer viewing online content, especially when it comes to E-commerce, in their native languages. And why not! Online visitors are very impatient. So offer them what they love, what is easily readable, and content that they can grasp quickly.
Now, as Magento 2 is a worldwide popular platform used by online businesses in multiple languages, translating the store’s content is inevitable.
Translating the store’s content can lead to more sales because international customers can better understand the product details and can relate to your business on a higher level.
Now, if you have tried translating using CSV but failed, you probably missed a step. And that’s why you need to follow this method to translate using XML in Magento 2.
Method to translate using XML in Magento 2:
As a Magento developer, it is a common practice for translating words through .csv file located at
Just add i18n folder in custom extension and in that, create .csv file with a translation of words like “Click Here”, “Klik hier”.
Observe that, the name of CSV starts with language name like en_US.csv,ar_SA.csv etc.
Despite following these steps, if some words are not translating in your store, then probably you might have missed, as shown below:
If you want to translate “city” field in dutch language from English and you’ve passed that field like below:
1 |
<item name="label" xsi:type="string" >City</item> |
In CSV file you’ve done every step perfectly like “city”, “stad” but word city is not translating then once check your XML file.
The correct method, which you have forgotten is:
1 |
<item name="label" xsi:type="string" translate="true">City</item> |
That’s it.
Adding translate=”true” is what you had skipped but not after following this post!
And yeah…let me remind you to use echo __(‘your word’) in phtml file too 🙂
If you’re looking for the method to translate JS error message or text In Magento 2 then visit our blog.
Other related posts:
Feel free to ask your doubts in the Comments section below. I’d be happy to help.
Do share the tutorial with fellow Magento developers via social media.
Thank you.
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
Prev
How To Create Downloadable Products in Magento 2
How to Set Minimum Product Quantity & Fixed Incremental Quantity in Magento 2
Next