Angular 6-i18n与ngx-translate [英] Angular 6 - i18n vs. ngx-translate

查看:112
本文介绍了Angular 6-i18n与ngx-translate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用angular 6进行大型项目。该项目需要大量的i18n集成。我正在就如何进行做出正确的决定。



我看到的方式是可以在以下选项之间进行选择:


  1. ngx -translate( https://github.com/ngx-translate/core

  2. Angular i18n( https://angular.io/guide/i18n

我倾向于选择选项2; Angular的i18n。这是因为它是Angular自己的内置软件包,对我来说更好。显然,对于SEO来说也更好,而在没有任何变通的情况下,它的性能也稍好一些。另外,现在发布了,我认为ngx-translate可能已被弃用。
这里的很多信息: Angular 5国际化



但是我的保留意见是>



有没有办法用角度i18n进行实时语言切换?即在页面上切换语言而未从服务器重新加载/重新获取数据?他们就是所谓的JIT吗?



有人尝试过 https://github.com/robisim74/angular-l10n ?看起来也很好。



非常感谢。
最好的问候。

解决方案


这太新了吗?


这是基于意见的,因此不合主题


显然我必须有一个单独的网站


您需要一个单独的应用程序(即index.html +捆绑软件) 。但是您可以通过单个URL为所有这些应用程序提供服务,从而决定在服务器上提供哪个应用程序。当希望在基于Ivy的新动态i18n可用时,这将(希望)随着Angular 7发生改变。


是否每次都动态插入模板文件?


不确定您的意思。 Angular AOT编译器在编译时将为您构建的语言环境的翻译存储在生成的模板类中。


如何使用角度i18n进行实时语言切换?


否,而且下一个版本的i18n也无法实现。同样的,独特的应用程序将能够以多种语言运行,但是在启动时仍必须选择该语言,并且您必须重新启动该应用程序才能选择另一种语言。


有没有办法用角度i18n进行实时语言切换?


否。至少没有效率。


这就是所谓的JIT吗?


否。 JIT编译器是在启动时在浏览器中将HTML模板编译为JavaScript的工具。在生产中,您使用AOT编译器(也用于将翻译集成到生成的JS类中),它对模板进行类似的编译,但是在构建时而不是在运行时。


I am working on a large project using angular 6. This project needs significant i18n integration. I am trying to make the right decision as to how to proceed.

The way I see it is that I can choose between:

  1. ngx-translate (https://github.com/ngx-translate/core)
  2. Angular i18n (https://angular.io/guide/i18n)

I am leaning toward choosing option 2; Angular's i18n. This is because it is Angular's own built in package and that just sits better with me. Apparently it is also better for SEO and marginally better for performance without any work around. Also, now it is released I think ngx-translate might be deprecated. Lot's of info here: Angular 5 internationalization.

However here are my reservations:

  • Apparently Angular's version is quite new / still catching up (https://github.com/ngx-translate/core/issues/495). Is it too new to take on?
  • Apparently I have to have a separate website build for each language (https://angular.io/guide/i18n#template-translations)??? I really don't think that would be a good thing. Is that right? or is it a case that template files are dynamically inserted each time? I know that with ngx-translate the translated words are just stored in .json files - I like the neatness of that. I don't think we want a bunch of different website builds.

Is there a way to do live language switching with angular i18n? i.e. switching language on the page without reloading / refetching data from the server? Is that what they call JIT?

Has Anyone tried https://github.com/robisim74/angular-l10n? looks very good also.

Many thanks. Best regards.

解决方案

Is it too new to take on?

This is opinion-based, and thus off-topic

Apparently I have to have a separate website

You need a separate application (i.e. index.html + bundles). But you could serve all those applications from a single URL, deciding which one to serve on the server. That will (hopefully) change with Angular 7, when the new dynamic i18n, built on top of Ivy, is available.

is it a case that template files are dynamically inserted each time?

Not sure what you mean. The translations of the locale you build for are stored in the generated template classes at compile time, by the Angular AOT compiler.

Is there a way to do live language switching with angular i18n?

No, and that won't be possible with the next version of i18n either. The same, unique application will be able to run in several languages, but the language will still have to be chosen at startup, and you'll have to restart the app to choose another language.

Is there a way to do live language switching with angular i18n?

No. Not efficiently at least.

Is that what they call JIT?

No. The JIT compiler is what compiles your HTML templates into JavaScript at startup, in the browser. In production, you use the AOT compiler (which is also used to integrate the translations into the generated JS classes), which does a similar compilation of the templates, but at build time rather than runtime.

这篇关于Angular 6-i18n与ngx-translate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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