我在使用 angular-translate 时遇到一个奇怪的问题(没有显示翻译),参数插值作为日期对象。
但首先要做的是:here是 plunker。
.
在翻译提供程序中使用清理策略“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.
因此,我想如果您想在第一次和第三次测试中使用这些变体,您可能必须坚持使用“转义”策略。或者,将您的日期字符串格式化为不包含导致问题的任何字符。
当我编辑您的 plunker 以使用“转义”时,您的所有四个测试都运行良好。
关于javascript - 使用 escapeParameters sanitizer 插值参数时出现 Angular 翻译问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39016874/