Domanda

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" />
È stato utile?

Soluzione

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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange
scroll top