链接插值 i18n [英] Link interpolation i18n
本文介绍了链接插值 i18n的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的项目中使用 ember-i18n 来处理多种语言,我需要在翻译中插入一个链接(带插值).
有什么想法吗?
解决方案
<块引用>您不能在翻译中使用 {{link-to}}
助手,因为它发出一个 DOM 节点,而不是一个字符串.
但是您可以使用 ember-href-to 插件来生成 URL.>
在 JavaScript 中:
//some-thing/component.js:从 'ember-href-to/helpers/href-to' 导入 { hrefTo };文本: 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 });})
或者在 Handlebars 中(你需要一个 htmlSafe 助手):
{{t 'some.translation'link=(htmlSafe (join '<a href="' (href-to 'some.route') '">Link Text</a>'))}}
I use ember-i18n to handle multiples langages in my project, and I need to insert a link inside a translation (with interpolation).
Any idea ?
解决方案
Response from @jamesarosen on Github :
You can't use the
{{link-to}}
helper inside a translation because it emits a DOM node, not a String.
But you can use ember-href-to addon to generate URLs.
In 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 });
})
Or in Handlebars (you'll need an htmlSafe helper):
{{t 'some.translation'
link=(htmlSafe (join '<a href="' (href-to 'some.route') '">Link Text</a>'))}}
这篇关于链接插值 i18n的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文