gpt4 book ai didi

ember.js - 链接插值 i18n

转载 作者:行者123 更新时间:2023-12-02 05:55:04 24 4
gpt4 key购买 nike

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

有什么想法吗?

最佳答案

Response来自 Github 上的@jamesarosen:

You can't use the {{link-to}} helper inside a translation because it emits a DOM node, not a String.

但是你可以使用ember-href-to用于生成 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 });
})

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

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

关于ember.js - 链接插值 i18n,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40265294/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com