Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How do I put a dynamic variable into Angular localization's translation? My team is using $localize and custom ID's under the following (highly simplified) arrangement.

travel.component.ts

export class TravelComponent {
  totalCountries = 3; // called from API
  description = $localize`:@@VISITED: User visited ${totalCountries} countries.`;
}

travel.component.html

<div i18n>{{ description }}</div>

translations.component.html

<pre i18n="@@VISITED">User visited XXXXX countries.</pre>

How do I replace XXXXX with totalCountries?


Failed Attempt

With this resource, I tried:

travel.component.ts

description = $localize`:@@VISITED: User visited ${totalCountries}:totalVisits: countries.`;

travel.component.html

<pre i18n="@@VISITED">User visited <x id="totalVisits"/> countries.</pre>

However, I get the error Errors parsing template: Only void and foreign elements can be self closed "x".

question from:https://stackoverflow.com/questions/65713867/angular-localize-internationalization-with-dynamic-variable-using-custom-id

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
483 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...