4

I can translate strings in Knockout html templates like this:

<!-- ko i18n: 'Email' --><!-- /ko -->
<span data-bind="i18n: 'Email'"></span>

And the translations come from pub/static/<area>/<vendor>/<theme>/xx_XX/js-translation.json.

But I do not know how to translate a value in an HTML attribute, e.g. the placeholder attribute on an input tag, like

<input type="text" placeholder="Email" />

1 Answer 1

7

You can write like this

<input type="text" data-bind="attr:{placeholder: $t('Email')} " />

Run below commands

php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy
php bin/magento cache:clean
4
  • Worked for me! I didn't need to run any setup commands but the translation is already in my js-translation.json file and I have layout, block_html and full_page cache disabled while developing. Commented Jun 28, 2017 at 9:57
  • Yes, but when you changes any content of .html file it require deploy static content. without deploy you can't see your changes. Commented Jun 28, 2017 at 9:59
  • You don't need to run a static content deploy unless you're in production mode.
    – Ben Crook
    Commented Jun 28, 2017 at 10:12
  • @BenCrook Have you any document explanation for it? Commented Jun 28, 2017 at 10:14

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.