Docs
Translations
Translations
Demonstrates how to use translations in a Magento template.
Open these files from the /vendor/maddlen/module-zermatt-examples/view/frontend directory:
- zermatt.json
/vendor/maddlen/module-zermatt-examples/view/frontend/web/zermatt/zermatt.json - translation.phtml
/vendor/maddlen/module-zermatt-examples/view/frontend/templates/translate.phtml - translation.js
/vendor/maddlen/module-zermatt-examples/view/frontend/web/zermatt/modules/translation.js - en_US.csv
/vendor/maddlen/module-zermatt-examples/i18n/en_US.csv
zermatt.json
We declare the ZermattExamples_Translation module which points to /vendor/maddlen/module-zermatt-examples/view/frontend/web/zermatt/modules/translation.js
translation.js
- We just expose an AlpineJS component with a
messageproperty which uses$t()and its interpolation capability. $t()uses native Magento translation layer to retrieve strings fromen_US.csvas made available by Magento injs-translation.json.
translate.phtml
- We call
Zermatt.Module('ZermattExamples_Translation')... - ... and use its
messageproperty as declared intranslation.js