ngTranslate 复数和 HTML
ngTranslate with pluralization and HTML
我有一个带有 ngTranslate 复数形式的模板:
en-US "{count, plural, one{1 accepted} other{# accepted}}"
pt-BR "{count, plural, one{1 aceito} other{# aceitos}}"
但我想把数字放在 span
标签之间:
en-US "{count, plural, one{<span>1</span> accepted} other{<span>#</span> accepted}}"
pt-BR "{count, plural, one{<span>1</span> aceito} other{<span>#</span> aceitos}}"
这样,如果我使用 translate
属性指令:
<span translate="LBL_ACCEPTED" translate-values="model.i18nValues" translate-interpolation="messageformat"></span>
HTML 已加密,我可以在最终结果中看到 HTML 标签。所以我使用 ng-bind-html
指令:
<span ng-bind-html="'LBL_ACCEPTED' | translate:model.i18nValues:'messageformat' | trustHtml"></span>
同样的结果。 HTML 显示给用户。
有什么方法可以解密这个 HTML 标签吗?
编辑:
该问题并非特定于 ngMessageFormat 的使用。如果我有像 "<b>{{count}}</b> accepted"
这样的翻译,标签就会被转义。我尝试添加 translate-compile
指令,但似乎没有任何效果。
找到问题了。
在模块配置中,我正在设置:
$translateProvider.useSanitizeValueStrategy('escape');
在这里浪费了几个小时。
我有一个带有 ngTranslate 复数形式的模板:
en-US "{count, plural, one{1 accepted} other{# accepted}}"
pt-BR "{count, plural, one{1 aceito} other{# aceitos}}"
但我想把数字放在 span
标签之间:
en-US "{count, plural, one{<span>1</span> accepted} other{<span>#</span> accepted}}"
pt-BR "{count, plural, one{<span>1</span> aceito} other{<span>#</span> aceitos}}"
这样,如果我使用 translate
属性指令:
<span translate="LBL_ACCEPTED" translate-values="model.i18nValues" translate-interpolation="messageformat"></span>
HTML 已加密,我可以在最终结果中看到 HTML 标签。所以我使用 ng-bind-html
指令:
<span ng-bind-html="'LBL_ACCEPTED' | translate:model.i18nValues:'messageformat' | trustHtml"></span>
同样的结果。 HTML 显示给用户。
有什么方法可以解密这个 HTML 标签吗?
编辑:
该问题并非特定于 ngMessageFormat 的使用。如果我有像 "<b>{{count}}</b> accepted"
这样的翻译,标签就会被转义。我尝试添加 translate-compile
指令,但似乎没有任何效果。
找到问题了。
在模块配置中,我正在设置:
$translateProvider.useSanitizeValueStrategy('escape');
在这里浪费了几个小时。