How do Magento2 translations work?
-
28-09-2020 - |
Question
There are plain strings i.e. in view/adminhtml/ui_component/product_listing.xml
and I am wondering how they get translated into other languages.
Also what is the correct way of using translations in PHP code (Blocks, Models etc.) or template files? In Magento 1 it was like $this->__('asd');
.
Solution
The correct way to use the translation is __('text here')
. Simple as that. no $this
or any other object. Just __
function.
the fact that you see plain texts in xml files should not be a problem.
the xml files are used by at least one php script. And the php script knows the structure of the xml files including what needs to be translated or not.
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange