Created
June 8, 2021 14:16
-
-
Save cagartner/d9344fa7df4b76cefe40d9a38f703057 to your computer and use it in GitHub Desktop.
Translate strings on Magento 2 on Javascript components
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define (['jquery', 'mage/translate'], function ($, $t) { | |
return function () { | |
// 1. $.mage.__('<string>'); | |
var string1 = $.mage.__('<string>'); | |
// 2. Use the $.mage.__('') function when adding a string: | |
var string2 = $.mage.__('<string>'); | |
// or | |
var string3 = $t('<string>'); | |
// If your string contains a variable, to add a placeholder for this variable to the string stored in the dictionary, use the following syntax: | |
var string4 = $.mage.__('Hello %1').replace('%1', yourVariable); | |
// or | |
var string5 = $t('Hello %1').replace('%1', yourVariable); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment