Bullet Proof Translation & Localization of a Magento 2 Store

Magento 2 uses an i18n approach to translating modules and themes quickly and easily. It can be used for language translations such as English to French, but also for translating/rewriting local idioms/vocabulary in the same language. For example, in American English, a “trunk” of a car would be called a “boot” in British English.

 

So let’s get started translating Magento 2

1) Create a collection of translatable phrases by logging in to the root of your Magento 2 store via SSH and run:

This will create a file called en_US.csv in the root of your installation. The naming designation is yy_XX with yy being the language and XX being the region, a csv for British English would be named en_GB.csv. Download the resulting file, as it will be used in the next steps.

2) Create a Magento 2 language pack

2 a) Create the following folder structure in your Magento 2 installation

Copy the en_US.csv you downloaded into this directory. CompanyName should be updated to match your developer identity/company and en_US should be updated to match the language and region you are targeting.

2 b)Create a language.xml file at the following location:

Update CompanyName to match your developer identity and en_US to match your targeted language/location

2 c) Create a registration.php file at the following location:

Update CompanyName to match your developer identity and en_US to match your targeted language/location

In the newly created registration.php add the code below updating CompanyName to match your developer identity and language/location. Note, use all lowercase letters for this instance of: companyname_language_location

 

2 d) Create a composer.json file at the following location:

Add the following code the composer.json file updating CompanyName and en_us(language_location) to match your needs:

 

3) Make translations required to the language pack .csv For example, if we wanted to update the label “Apply Discount Code” in the Magento 2 checkout to “Apply Promotional Code,” we would search for that in the CSV and locate the following:

How you read the line is as follows: Each string is divided into 4 comma-separated columns.

Column 1 is the core string and matches the default definitions assigned by Magento 2 and module/theme developers, and should never be changed.

Column 2 is what you want the string to read as in a specific location.

Column 3 & 4 indicate where the translatable string was defined; these should not be changed.

Based on our need we would change the line to the following:

Upload the files to the server, navigate to “Cache Management” in the administration backend of the store, and refresh the Translation cache. Then in SSH at the root of the store run the following commands:

Remember to update en_US to match your language and localization and you have successfully translated your Magento 2 store!

Hans-Eirik Hanifl

view all posts

Hans-Eirik Hanifl is a forward thinking e-commerce and marketing consultant. As an advocate for the free exchange of knowledge, he founded E-Commerce Gorilla as a place where like-minded individuals can ask questions and share their expertise on practical solutions in the area of e-commerce and marketing. He is the owner of TRM Marketing and an avid supporter of the open source community.

0 Comments Join the Conversation →


Leave a Reply

Stay in the loop!

E-Commerce Gorilla Avatar

Join the E-Commerce Gorilla e-mail newsletter. We provide monthly updates on new articles featuring all aspects of online sales and E-Commerce setup. We cover the do's and don'ts of effective online sales, along with great giveaways. As a newsletter subscriber you are automatically entered for any competitions and giveaways.* Join our community of engaged online marketing experts, great content, and great giveaways. You can't go wrong.