I'm trying to translate text that comes from a variable in Knockout html file, but I can;t find the right way. Here's some things I tried:

<dt class="label" data-bind="html: i18n(option.label)"></dt>
<dt class="label" data-bind="i18n: option.label"></dt>
<dt class="label"><!-- ko i18n: option.label --><!-- /ko --></dt>

option.label returns a string like 'width' or 'height'. There words are included in a .csv translation file.

1 Answer 1


both the following answer you give are good:

<dt class="label" data-bind="i18n: option.label"></dt>
<dt class="label"><!-- ko i18n: option.label --><!-- /ko --></dt>

The i18n attribute in Magento javascript need a string. So the important point to verify is that the value given by option.label is a string and that string is in your *.csv.

It's like doing:

<dt class="label" data-bind="i18n: 'My label'"></dt>
<dt class="label"><!-- ko i18n: 'My label' --><!-- /ko --></dt>

More details in the Magento Dev documentation: https://devdocs.magento.com/guides/v2.3/frontend-dev-guide/translations/translate_theory.html#add_strings_ui_html

But sometime, you need to check if your translation is well generated in your pub/static folder.

  • I applied your suggestion and it seemed to be updated when making the change directly in the vendor folder, however, not if I apply it to a theme override. Further, it seems not to be translated. Do you have more information on how to provide translations outside the i18n CSV?
    – Max
    Nov 22, 2021 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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