In this article, you will learn how to perform Magento 2 theme files translation.
Usually, the translations are being stored in the .csv files on your server. However, if for some reason there’s no CSV translation file translated for your language – you will need to create the .csv file from scratch. To create the CSV translation file – please follow the steps below.
Make sure to disable Magento 2 cache before proceeding with .csv file translation.
Step 1. Create the required file for translation
First, in your Magento 2 admin panel, you need to find the .csv file and copy it to create the required file for the translation. Please, check the example below.
Name the file to include the target language code. This is an example file with a German translation:
Step 2. Translate the phrases according to the requirements
While translating, make sure all the strings in your .csv file start and end with double quotes, and are separated with comma [,], not semi-colon [;] or any other mark.
"Add to Cart", "Translated Text"
You can change the default theme strings according to the requirements of your website, for example:
"My Cart","My Basket" "My Account","Your Account"
All the lines are case-sensitive, you should copy the phrase exactly as it is in the “en_US” version. In the source “en_US” version the text looks like this:
"%s Item(s)","%s Item(s)"
Whereas the translated text should look like this:
"%s Items","%s Product(s)"
If you need to set off a word or phrase by quotation marks, put two double quotation marks for such a string.
You can also use HTML coding to alter your text. Check an example:
Step 3. Save the CSV file in UTF-8 encoding
Make sure your text editor saves .csv file in UTF-8 encoding, as it supports different alphabets. If you edit the file using Excel, convert it into UTF-8 encoding once you finish editing.
How to translate the same element differently for different pages
While performing translation in this file – any word or phrase will be translated for the entire theme. If you need to translate the same element in different ways for different pages, you can use this example:
"Mage_Catalog:Add to Cart","Add to Basket" "Mage_Checkout:Add to Cart","Add to my shopping cart"
To read more information about Magento 2 translations, please click here.