角即时翻译方法不起作用 [英] angular translate instant method does not work

查看:159
本文介绍了角即时翻译方法不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有角翻译网站。它完美的作品。我们有我们想用某种语言的关键注视一个变量。比方说,该网站的语言有恩和深航作为选项,我想有一定的翻译与深航不管语言选择返回。

We have a website with angular translate. It works perfectly. We have a variable that we want to fixate with a certain language key. Let's say the site's language has 'en' and 'zh' as options, I want a certain translation to return with 'zh' no matter the language choice.

通过浏览 API参考,我发现了一个叫即时做到这一点的方法。然而,当我们尝试调用它不能正常工作

By browsing the API reference, I found a method called Instant to do just that. However, it doesn't work when we try to call

$translate.instant('zh', 'TRANSLATION_ID')

它返回一个错误

TypeError: Object function (a,b,e){var f=d?n[d]:n,i=e?w[e]:u;if(f&&f.hasOwnProperty(a))return i.interpolate(f[a],b);if(h&&!v&&g.get(h)(a,d),d&&c&&d!==c){var j=n[c][a];if(j){var k;return i.setLocale(c),k=i.interpolate(j,b),i.setLocale(d),k}}return l&&(a=[l,a...<omitted>...a} has no method 'instant'

我不知道如何正确使用方法isntant

I wonder how to use the isntant method correctly.

推荐答案

好像你没有正确使用的方法,或者可能只是误会了吧。

It seems like you don't use the method correctly, or probably just misunderstood it.

$ translate.instant('ID')预计翻译id作为第一参数和插值PARAMS为第二参数。然后,它翻译ID的同步而不是异步(这是 $翻译()一样)。

$translate.instant('ID') expects the translation id as first parameter and interpolation params as second parameter. It then translate the id synchronously instead of asynchronously (which is what $translate() does).

您想明确地翻译在一定的语言环境的翻译ID不管是什么语言的关键是目前使用的是什么。这是目前的不可以支持的尚未

What you want is explicitly translating a translation id in a certain locale no matter what language key is currently used. This is currently not supported yet.

希望使事情说清楚。

这篇关于角即时翻译方法不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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