Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences ngx-translate vs i18n

There are multiple methode to translate an (Angular) app, the big main methodes are :

ngx-translate

and

Angular 2 native i18n

As far I understood i18n is easier for SEO because of the clean url browsing with

e.g

app.com/de

app.com/en

on the other hand with ngx-translate it is easier to switch between languages.

I know that the creator of ngx-translate was hired by Angular for their i18n. Can anybody say me what the main differences are (pro/cons)?

like image 475
Domi Avatar asked Jul 05 '17 10:07

Domi


People also ask

What is NGX-translate?

ngx-translate is the library for internationalization (i18n) and localization in Angular. It simplifies your Angular application to work for localization. It's easy to set up and use in an Angular application.

What is translate pipe in Angular?

The service also contains a method called translate. It is later called by the pipe to get the translation for a specific key. It always uses the language specified in the 'language'-variable of the service, to lookup the translation. That's it.


3 Answers

I believe that this issue answers your question: https://github.com/ngx-translate/core/issues/495

like image 141
Sarah Cassar Avatar answered Oct 09 '22 12:10

Sarah Cassar


This question is old at this point, but I think the answer is in need of an update.

ngx-translate has been largely abandoned. The author of ngx-translate, ocombe, is hard at work at Google to improve the built in Angular method. He transitioned ngx-translate to maintenance only. As of this date (May 2021), he has not done any maintenance on ngx-translate for 11 months including no update for Angular 11.

ngx-translate no longer appears viable for projects newly internationalizing Angular.

like image 22
Eric E AT MT Avatar answered Oct 09 '22 13:10

Eric E AT MT


According to @ocombe, The idea behind ngx-translate library has always been to provide support for i18n until Angular catches up, after that this lib will probably be deprecated. For now, there are still a few differences between Angular i18n and this library:

  • Angular only works with one language at a time, you have to completely reload the application to change the lang. The JIT support only means that it works with JIT, but you still have to provide the translations at bootstrap because it will replace the text in your templates during the compilation whereas this lib uses bindings, which means that you can change the translations at any time. The downside is that bindings take memory, so the Angular way is more performant. But if you use OnPush for your components you will probably never notice the difference

  • Angular only supports using i18n in your templates for now, I'm working on the feature that will allow you to use it in your code, but it's still a work in progress. This lib works both in code and templates

  • Angular supports either XLIFF or XMB (both are XML formats), whereas this lib supports JSON by default but you can write your own loader to support any format that you want (there's a loader for PO files for example)

  • Angular supports ICU expressions (plurals and select), but ngx-translate library doesn't

  • Angular supports html placeholders including angular code, whereas this library only supports regular html (because it's executed at runtime, and not during compilation, and there is no $compile in Angular like there was in AngularJS)

  • The API of ngx-translate library is more complete because it is executed at runtime it can offer more things (observables, events, ...) which Angular doesn't have (but doesn't really need given that you can not change the translations)

like image 18
Chuma Umenze Avatar answered Oct 09 '22 12:10

Chuma Umenze