Hello, Magento Folks,

Last time we learned how you can Create Custom log files using a module in Magento 2. Today, we are going to learn how to write translatable strings in Email, PHTML, UiComponents, js, etc.

In any version of Magento 2, you can setup multi-languages, but to translate strings in Magento 2, you need to know some functions that are useful in the source code. There are different types of approaches to write a translatable string in Magento 2 frontend. Like Email, PHTML, UiComponents, Js, etc.

So, let’s check out how to write translatable strings with the help of codes.

Note: You can check all translatable string at

pub\static\frontend\Themes\Yourtheme\<language>\js-translation.json

Let’s first look at how to translate strings in PHTML:

Let’s first look at how to translate strings in Email templates:

Let’s first look at how to translate strings in UI Component templates:

Let’s first look at how to translate strings in JS files:

Note: you must use the $t object of Mage/Translate. You can’t change the name of $t like,

Will work ?

Will Not work ?

So, this was it for the day. Now, you are able to write translatable strings in Email, PHTML, UiComponents, and Js, etc. The code strings above are just for the reference only you can customize it and implement it for your use as per your needs. If you face any problem while during so then contact our support team.

Lastly, feel free to comment below and let us know what you feel about this article. Also, you can share this with your Magento colleagues and partners.

Happy Coding?

Click to rate this post!
[Total: 3 Average: 3.7]