I've knockout template which contains the following line:

<option value='industrial' data-bind="i18n: 'Industrial'"></option>

anyone knows how to add variable to 'Industrial' eg.

<option value='industrial' data-bind="i18n: 'Industrial' + window.checkoutConfig.hrFlag"></option>

the above line didn't work.

  • have you tried doing like this : data-bind="i18n: 'Industrial + window.checkoutConfig.hrFlag'? – fmsthird Mar 13 '19 at 5:25
  • @magefms the variable string will not show – hkguile Mar 13 '19 at 5:27
  • you should declare the variable to the ko bindings function in order to append it in the data-bind – fmsthird Mar 13 '19 at 5:31

To ensure that the text you add in a .js file is collected by the i18n tool and added to the dictionary:

  1. Link the mage/translate library

    define (['jquery', 'mage/translate'], function ($) {...});

  2. Use the $.mage.__('') function when adding a string:


If your string contains a variable, to add a placeholder for this variable to the string stored in the dictionary, use the syntax similar to the following:

 $.mage.__('Hello %1').replace('%1', yourVariable);

In this example, the 'Hello %1' string is added to the dictionary when the i18n tool is run.

Reference : https://devdocs.magento.com/guides/v2.3/frontend-dev-guide/translations/translate_theory.html

For phtmls $t does the same thing as mage/translate so you can do following ;

<option value='industrial' data-bind="i18n: $t('Industrial %1').replace('%1', window.checkoutConfig.hrFlag)"></option> 
  • showing error with red cross. by the way, it seems possible to do like this syntax data-bind="attr: {html: $t('Industrial')} , but attr:html is wrong. – hkguile Mar 13 '19 at 5:44
  • ok try the edit. – Vivek Kumar Mar 13 '19 at 6:00
  • @hkguile the edit worked for you right? – Vivek Kumar Mar 13 '19 at 7:12
  • yes, it works....... – hkguile Mar 13 '19 at 7:16
  • Ok will add more reference. – Vivek Kumar Mar 13 '19 at 7:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.