0

I am in the process of using i18n to add translation to my project but I have a problem with trying to apply this technique to an input box with a placeholder that is dynamically determined by a pipe:

<input
  i18n-placeholder="@@testPlaceholder"
  placeholder={{'text to be transformed here by pipe'} | PipeFormatter}}
/>

where PipeFormatter is a custom pipe i have created to transform the text based on requirements.

How would I be able to provide the translation for the placeholder in this instance?

  • You can use you pipe inside your component. See [this answer](https://stackoverflow.com/a/35152297/10122791) – Augustin R Aug 23 '18 at 13:21
  • 1
    Have you tried using ngx-translate? The docs mos tlikely will explain what to do: https://github.com/ngx-translate/core. You could do your translate magic inside your custom pipe. – gerb0n Aug 23 '18 at 13:22
  • I was looking at ngx-translate but i was wondering if there was any way to do it using the i18n tools? For example, I can use the translate select feature to do the following e.g: where object.label is the value to be checked and the following parts after the select are all possible values. Can this be done for the placeholder template in the HTML code? – AmeBaathHai Aug 23 '18 at 13:29

1 Answers1

0

first of all you should understand that you should give the palceholder a string as value. that means: placeholder = "". second you can have dynamic code in html when you use the {{}} braketes. thrid: if you have some string in your pipe, you should use single quote and not double quote. like this:

In this example you see that I'm using the translation pipe in order to give the place holder a dynamically value based on the selected language: This code works, because I'm using it.

placeholder="{{'customer.address_dialog.address_placeholder' |     translate}}"
Hamid
  • 43
  • 6
  • Remember that Stack Overflow isn't just intended to solve the immediate problem, but also to help future readers find solutions to similar problems, which requires understanding the underlying code. This is especially important for members of our community who are beginners, and not familiar with the syntax. Given that, **can you [edit] your answer to include an explanation of what you're doing** and why you believe it is the best approach? – Jeremy Caney Mar 07 '23 at 00:06