how to translate the html5 placeholders dynamically

angular i18n translate placeholder
google translate placeholder
angular dynamic placeholder
angular-translate dynamic key
angularjs dynamic placeholder
angular i18n dynamic

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 ?

Did you try:

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

how to translate the html5 placeholders dynamically – Angular , I'm using angular-translate to translate the page content in to different languages. <input type ='text' placeholder = ' {username | translate}'>. The translate() method remaps the (0,0) position on the canvas. Note: When you call a method such as fillRect() after translate(), the value is added to the x- and y-coordinate values.

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:

Using HTML's translate attribute, I'm using angular-translate to translate the page content in to different languages. <input type ='text' placeholder = ' {username | translate}'>. This works fine  For a long form I am generating input fields dynamically using an ngFor loop and would like to translate field labels and placeholders dynamically. For this I am trying to generate the translation keys dynamically. My current attempt in html code looks like this:

+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

Don't Use The Placeholder Attribute, The translate attribute in HTML5 indicates that the content of the element should and placeholder attribute values in HTML), although this is not recommended. If you want to use same placeholder text for all text inputs, you can use $('input:text').attr('placeholder','Some New Text'); And if you want different placeholders, you can use the element's id to change placeholder $('#element1_id').attr('placeholder','Some New Text 1'); $('#element2_id').attr('placeholder','Some New Text 2');

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} }}" >

Question: How to dynamically construct translation keys for input , Introduced as part of the HTML5 specification, the placeholder Because of this, placeholder content won't be translated and will An interoperable input is created by programmatically associating a label element with it. Because I find it annoying/tiresome to add all the placeholders from the code behind. You can create a new TextBox Class that inherits the WebControls TextBox and then you can add the placeholder from the CodeBehind or from the HTML Side.

How can I translate a placeholder in angular 4 with jhi-translate?, Of course, the above doesn't work for the placeholder attribute as I am not using the translate directive as I am doing for the ion-label element. Step 2) Add CSS: In most browsers, the placeholder text is grey. To change this, style the placeholder with the non-standard ::placeholder selector. Note that Firefox adds a lower opacity to the placeholder, so we use opacity: 1 to fix this.

Forms, I have saved the translations in the Json files in i18n. My idea below does not work how to translate the html5 placeholders dynamically. I'm using  The placeholder attribute specifies a short hint that describes the expected value of an input field (e.g. a sample value or a short description of the expected format). The short hint is displayed in the input field before the user enters a value.

HTML, The placeholder attribute is part of an HTML5 spec. It displays 'Search. What's the best way to proceed to have the placeholder translated? I thought about a  Save this file in the Dynamic Content folder as dynamic_content.html. Create another new file by clicking on the New File icon in the upper left corner of the Notepad++ window (it looks like a white sheet of paper next to a green circle and a white + symbol inside the circle).

  • <input type ='text' placeholder = ' {username | translate}'>
  • username must be a string, so you have: <input type ='text' placeholder = "{'username' | translate}">
  • For me doesn't..<input name="login_form_email" type="email" placeholder="{{'login.default_email' | translate }}" required> not translating runtime
  • For me it is not working, the problem comes when you do it at runtime, not at start.
  • This approach is deprecated, see @armyofda12mnkeys' answer, there is a directive to translate the placeholder
  • That doesn't work on Internet explorer, the documentation is pretty clear about this point. When the interpolation is being proceed an error/crash will appear. You should use custom placeholder directive to handle it as you want
  • This answer is close, but technically it is a better practice to use ng-attr-placeholder as the attribute because then Angular can hold off on display the value until it is actually ready (after the translation). The jank when using the original placeholder attribute is usually so fast you can't see it, but it will be possible for a user to see the untranslated key for a moment if you do it like the posted answer.
  • This is the best solution to translate the placeholder attribute.