angular-i18n select syntax in attribute
Asked Answered
E

1

5

I was trying to use the i18n SELECT syntax to translate a placeholder for an input field:

<input placeholder="{userRole, admin{you are an admin} other {you are a user}}" i18n-placeholder="MYAPP.PLACEHOLDER|my placeholder">

this results to the following xlf file entry:

<trans-unit id="85f60a0a03b3b4e189252fc0157dd403e806bbcc" datatype="html">
    <source>{userRole, admin{you are an admin} other {you are a user}}</source>
    <context-group purpose="location">
      <context context-type="sourcefile">path/to/my/file.component.ts</context>
      <context context-type="linenumber">4</context>
    </context-group>
    <note priority="1" from="description">my placeholder</note>
    <note priority="1" from="meaning">MYAPP.PLACEHOLDER</note>
  </trans-unit>

So it seems like the SELECT syntax isn't recognized. When i use the syntax not to translate an attribute but the content of an element the .xlf tag looks like this:

<source>{VAR_SELECT, admin{you are an admin} other {you are a user}}</source>
Enceinte answered 1/2, 2018 at 15:39 Comment(0)
E
11

It seems like this an allready known issue with Angular

Allow ICU messages in attributes [blocked, requires an update of the pars

https://github.com/angular/angular/issues/16477

A workaround for this is to use a different tag to implement the translation:

<span i18n='SOME_TITLE|Description Text' #translatedPlaceholder>{VAR_SELECT, admin{you are an admin} other {you are a user}}</span>    
<input [placeholder]="translatedPlaceholder.textContent" />
Enceinte answered 1/2, 2018 at 16:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.