0

i have an angular 7 project with multi languages and i have also the validation messages translated in the i18n files so i am facing a problem with the length validation message which should be "this field must be less than xxx characters" as example some fields this length is 8 chars and other fields this length is 10 chars and so on.

so i want to find a way to make the validation message some how take a param and put this param in the message like i send that this field length is 10 chars and the validation message will be "this field must be less than 10 characters"

1 Answers1

0

You can use property binding inside your translations. So you would define the specific length inside the component for this field or inside a global setting for each field.

And then you can use a i18n definition like:

<div i18n="@@field.max-length">max {{maxLength}} characters</div>

You can then reuse this definition for all your inputs.

The generated xliff looks something like this:

<trans-unit id="@@field.max-length" datatype="html">
   <source>max <x id="INTERPOLATION" equiv-text="{{maxLength}}"/> characters</source>
   <target>max <x id="INTERPOLATION" equiv-text="{{maxLength}}"/> characters</target>
   [...]
</trans-unit>
Erbsenkoenig
  • 1,584
  • 14
  • 18