Ember.js 链路插值i18n

Ember.js 链路插值i18n,ember.js,handlebars.js,Ember.js,Handlebars.js,在我的项目中,我使用ember-i18n来处理多个语言,并且我需要在翻译中插入一个链接(带有插值) 有什么想法吗?来自Github上的@jamesarosen: 您不能在翻译中使用{{link to}帮助程序,因为它 发出DOM节点,而不是字符串 但您可以使用插件生成URL 在JavaScript中: // some-thing/component.js: import { hrefTo } from 'ember-href-to/helpers/href-to'; text: Ember.c

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

有什么想法吗?

来自Github上的@jamesarosen:

您不能在翻译中使用
{{link to}
帮助程序,因为它 发出DOM节点,而不是字符串

但您可以使用插件生成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 });
})
//某物/component.js:
从'ember href to/helpers/href to'导入{hrefTo};
text:Ember.computed('i18n.locale',function(){
const i18n=this.get('i18n');
const href=hrefTo(这是“some.route”);
const link=Ember.String.htmlSafe(``);
返回i18n.t('some.translation',{link});
})
或者在车把中(您需要一个htmlSafe助手):

{{t'some.translation'
链接=(htmlSafe(加入“”)}

我最近遇到了一个类似的问题,我就是这样做的:

翻译文件(en.json):

html安全是由附加组件提供的帮助程序

{{t 'some.translation'
  link=(htmlSafe (join '<a href="' (href-to 'some.route') '">Link Text</a>'))}}
"some.message.key": "Successfully created <a href='{{userlink}}'> {{username}} </a>."
{{html-safe (t "some.message.key" userlink=link username=name)}}