Roman Toengi
Roman Toengi

Reputation: 13

How to translate attributes with the Angular 2 ng-xi18n tool

A tag's text can be set for translation like this: <h1 i18n>Welcome</h1>

How are attributes like placeholder or label set? <input type="text" placeholder="Type your name" /> or <button type="submit" label="Send data"></button> (library primeng requires to set the button's label like this)

Thanks a lot.

Upvotes: 1

Views: 2062

Answers (2)

Brampage
Brampage

Reputation: 6974

To translate tag the placeholder attribute for translation you can add an i18n-placeholder attribute, like so:

<input type="text" i18n-placeholder="@@type-your-name" placeholder="Type your name" />

For other attributes it works the same way: i18n-x, where x is the name of the attribute to translate.

You can find the answer also inside the Angular i18n guide found here.

Upvotes: 5

Mertcan Diken
Mertcan Diken

Reputation: 15361

Hi I can suggest you a great lib for that ng2-translate its very easy to use. https://github.com/ocombe/ng2-translate

Upvotes: 0

Related Questions