how to translate the html5 placeholders dynamically

∥☆過路亽.° 提交于 2019-12-04 08:01:53

问题


I'm using angular-translate to translate the page content in to different languages.

<input  type ='text' placeholder = ' {username | translate}'>

This works fine when the page loads ..but it fails to translate when I use $translate.uses('fr') depending upon language dropdown changes.

Can any one kindly suggests the solution to translate the placeholders while the language changes dynamically ?


回答1:


Did you try:

<input type="text" placeholder="{{ 'my.i18n.key' | translate }}" ng-model="myModel">



回答2:


There is a directive in angular-translate to help with this. See this issue.

<input placeholder="Regular Placeholder" translate translate-attr-placeholder="text" translate-value-browser="{{app.browser}}">

Here is a preview of a working plunkr from that thread: http://plnkr.co/edit/J4Ai71puzOaA0op7kDgo?p=preview




回答3:


+ira 's solution works for me.

<input type ='text' placeholder = "{'USERNAME' | translate}">

where username is the key for the translation. So that translation JSON line might look like the following in Spanish

"USERNAME": "Nombre",

The two together puts Nombre as a placeholder inside the input box




回答4:


I Use this method:

In en.json:

{
   "ENTER_TEXT": "{{label}} را وارد کنید",
   "DISCOUNT_CODE": "کد تخفیف"
}

In template:

<input type="text" placeholder="{{'ENTER_TEXT' | translate: {label: 'DISCOUNT_CODE' | translate} }}" >


来源:https://stackoverflow.com/questions/21025277/how-to-translate-the-html5-placeholders-dynamically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!