链接插值i18n

Tim*_*rce 2 handlebars.js ember.js

我使用ember-i18n来处理项目中的多个语言,我需要在翻译中插入一个链接(使用插值).

任何的想法 ?

Tim*_*rce 7

来自@jamesarosen对Github的回复:

您无法{{link-to}}在转换中使用帮助程序,因为它会发出DOM节点,而不是String.

但是您可以使用ember-href-to addon来生成URL.

在JavaScript中:

// some-thing/component.js:
import { hrefTo } from 'ember-href-to/helpers/href-to';

text: Ember.computed('i18n.locale', function() {
  const i18n = this.get('i18n');
  const href = hrefTo(this, 'some.route');
  const link = Ember.String.htmlSafe(`<a href="${href}">Link Text</a>`);
  return i18n.t('some.translation', { link });
})
Run Code Online (Sandbox Code Playgroud)

或者在Handlebars中(你需要一个htmlSafe助手):

{{t 'some.translation'
  link=(htmlSafe (join '<a href="' (href-to 'some.route') '">Link Text</a>'))}}
Run Code Online (Sandbox Code Playgroud)