链接插补i18n [英] Link interpolation i18n

查看:94
本文介绍了链接插补i18n的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



任何想法? / p>

解决方案

回复来自@jamesarosen on Github:


你不能使用 {{link-to}} helper在一个翻译内,因为
发出一个DOM节点,而不是一个String。


但是,您可以使用 ember-href-to 插入生成URL。



在JavaScript中:

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

文本:Ember.computed('i18n.locale',function(){
const i18n = this.get('i18n');
const href = hrefTo(this ,'some.route');
const link = Ember.String.htmlSafe(`< a href =$ {href}>链接文本< / a>`);
return i18n .t('some.translation',{link});
})

或在Handlebars(你需要一个htmlSafe帮助器):

  {{t'some.translation'
link = (htmlSafe(join'< a href ='(href-to'some.route')'>链接文本< / a>'))}}
pre>

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆