angular-translate 翻译里面的指令

Directive inside a angular-translate translation

我正在为 i18n 使用 angular-translate 并希望在翻译中使用指令:

var translations = {
  TEST_1: 'Hello from <a href="/test">Test</a>',
  TEST_2: 'Hello from <user></user>'
};

app.directive('user', function() {
  return {
    template: '<a href="/test">Test</a>'
  };
});

完整的 plnkr 示例:http://plnkr.co/edit/jCCcvx7IEaAYUwyaQ7uH?p=preview

所以

<p translate="TEST_1"></p>
<p translate="TEST_2"></p>

应该是一样的。第一个(没有指令)有效,第二个无效。它包含 <user></user>,但 Angular 似乎并没有意识到它,也没有执行它的指令魔法。

尝试使用translate-compile指令:

<p translate="TEST_2" translate-compile></p>

来自docs

Starting with version 2, the translation itself can be post processed in context of the current scope (using $compile). This means any directive used in a translation value itself will now work as expected.