How to Translate Magento 2 Extensions Using CSV Files

In this article, you will learn how to translate your Magento 2 extensions.

Generally, Magento uses a translation dictionary so that you can localize your store. This dictionary is a .csv file with two columns: the original text in the source (en_US) locale and the translation of that text in a target locale. Therefore, you need to perform Magento 2 CSV files translation by adding and applying the translation phrases.

Step 1. Create a CSV file & copy phrases for translation

Create the your_lanuage_code.csv file in the app/code/Plumrocket/<Module_Name>/i18n directory:

Example for German
app/code/Plumrocket/<Module_Name>/i18n/de_DE.csv 

Copy the phrases you need to translate from the following file:

app/code/Plumrocket/<Module_Name>/i18n/en_US.csv 

If the file is missing, you need to add a set of phrases for translation manually into the app/code/Plumrocket/<Module_Name>/i18n/de_DE.csv file.

Step 2. Translate phrases in each string

Open this .csv file using any text editor (e.g. Notepad++) and translate the phrase in each string. All the phrases in your .csv file should be written in double quotes and should be separated by commas [,]

Translation example into German
"Add to Cart", "In den Warenkorb"

Step 3. Remove the js-translation.json file

Now you have to apply the translation you have entered in the .csv file. Please, proceed with the following steps:

In Developer mode, you can disable Magento Cache to display changes instantly (does not apply to JS translation).

In the terminal, switch to your Magento 2 root directory using the following command:

cd /FULL_PATH_TO_YOUR_MAGENTO2

Remove the following file:

pub/static/frontend/<vendor>/<theme_name>/<locale_code>/js-translation.json
Example file name for Luma theme in German
pub/static/frontend/Magento/luma/de_DE/js-translation.json

Step 4. Deploy the CSV file with translation

Next, run the following command to deploy the translated file (please skip this step if Magento is in developer mode):

php bin/magento setup:static-content:deploy --theme <vendor>/<theme_name> <locale_code>
Command example for Luma theme in German
php bin/magento setup:static-content:deploy --theme Magento/luma de_DE

Step 5. Flush Magento cache

Flush Magento Cache using the following command:

php bin/magento cache:flush

Please make sure to refresh the page after you have applied your translation. If necessary, please check Magento DevDocs for more information about Magento 2 translation.

About The Author: Anastasiia Yaremchuk

Deeply passionate about making a good copy. Now exploring new horizons of SEO and content marketing. Apart from the digital world, she is obsessed with travelling, films and caffeine. View more posts