如何在带有变量的 html 模板中使用 anguluar i18n?

How to use anguluar i18n in html template with variables?

是否可以在 angular 模板 i18n 字符串中使用变量?

在 TypeScript 中我可以使用模板字符串,例如:

public welcomeMessage = $localize`:@@test.welcome: Hello ${this.name}:user_name:! How's your day?`;

我可以在 html 模板中使用类似的东西吗?例如

<p i18n="@@test.welcome">Hello {{name}}:user_name:! How's your day?</p>

希望你明白我的意思。

我 运行 遇到了同样的问题,Angular i18n 文档对插值和插值占位符的命名有些不清楚。对于简单的文本插值,您可以使用:

<p i18n>Hello {{name}}! How's your day?</p>

但 AFAIK 目前无法命名插值占位符,它最终将成为插值文本:

<source>Hello <x id="INTERPOLATION" equiv-text="{{name}}"/>! How&apos;s your day?</source>

但是,您始终可以在提取的 XLIFF 文件中手动更改占位符 (equiv-text)。