angular-使用 escapeParameters 清理插入参数时出现翻译问题

angular-translate issue when interpolating parameters with escapeParameters sanitization

我在使用 angular-translate 时遇到一个奇怪的问题(没有显示翻译),参数插值作为日期对象。

但最重要的是:here 是骗子。

.

在翻译提供程序中使用清理策略'escapeParameters',

为什么 json 格式如下:

$scope.title = { day: 'tomorrow', today: new Date() };

我的翻译结果总是{},使用缩写形式

{{'VARIABLE_REPLACEMENT' | translate : title}}

<translate="VARIABLE_REPLACEMENT" translate-values="{ day: 'tomorrow', today: title.today }">

如您所见,使用 angular-translate 的其他方法似乎都可以正常工作。这是某种错误吗?还是我做错了什么?

看起来像是一个已知错误。在 https://angular-translate.github.io/docs/#/guide/19_security 他们说

Currently there is an issue with the sanitize mode, it will double encode UTF-8 characters or special characters. Recommendation: use the 'escape' [instead of 'escapeParameters'] strategy, until this is resolved.

因此,我想如果您想在第一次和第三次测试中使用变体,您可能必须坚持使用 'escape' 策略。或者,将您的日期字符串格式化为不包含导致问题的任何字符。

当我编辑你的 plunker 以使用 'escape' 时,你的所有四个测试都运行良好。

对于每个想知道的人,我在 angular-translate 的 github 存储库上开了一个问题:这个问题将在 2.11.2(当前版本的下一个版本)中修复。 有关此问题的更多信息 here