Differences ngx-translate vs i18n
Asked Answered
P

5

46

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)?

Pewter answered 5/7, 2017 at 10:7 Comment(2)
Is this about AngularJs or Angular 2? If it is about AngularJs there is also Angular translate. Otherwise if targeting Angular 2 only, please remove the angularjs tag from your question.Inesinescapable
For the record you could also use github.com/robisim74/angular-l10nCallie
I
23

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

Idiophone answered 10/7, 2017 at 9:4 Comment(3)
This is not answer, but should be a comment instead.Whelk
Please avoid link-only answers. This meta answer meta.stackexchange.com/a/8259 explains in detail why that is a bad practice, from link rot to "Links are fantastic, but they should never be the only piece of information in your answer" and beyond.Parting
at the time when the discussion you linked happened, Angular was at version 4and ngx-translate was at version 6, meaning both the native i18n solution and the library have evolved sinceArdeliaardelis
C
32

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.

Calliper answered 6/5, 2021 at 16:9 Comment(4)
thanks for sharing this, it's helpful context - for those reading this, it's still (as of Dec '21) in maintenance mode - see link for latest commentsBavaria
here github.com/ngx-translate/core/issues/… he states the project is in "maintenance mode", meaning that there are no new features implemented, still there is maintenance to ensure compatibility with new versions of AngularPhonetics
This answer is no longer correct. Version 15 was released in May 2023, although it was the first release for 2 yearsAttest
I find this a little misleading. ngx-translate is still widely used, and hasn't become obsolete; it just became stable in most of the existing features. And regarding updates, there have been maintenance releases (for Angular version compatibility) since this answer was postedArdeliaardelis
I
23

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

Idiophone answered 10/7, 2017 at 9:4 Comment(3)
This is not answer, but should be a comment instead.Whelk
Please avoid link-only answers. This meta answer meta.stackexchange.com/a/8259 explains in detail why that is a bad practice, from link rot to "Links are fantastic, but they should never be the only piece of information in your answer" and beyond.Parting
at the time when the discussion you linked happened, Angular was at version 4and ngx-translate was at version 6, meaning both the native i18n solution and the library have evolved sinceArdeliaardelis
H
19

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)

Hemphill answered 5/11, 2018 at 21:31 Comment(0)
A
9

I'll point out the differences, but whether they are pros and cons totally depends on the type and scale of your project and developer team.

ngx-translate i18n
Relies on bindings in order to translate at runtime. The translation is done after build, creating a different application for each language. Each of the translated apps will be in a directory (for example /pt/ and /en/), this requires a redirectioning app.
Sacrifices performance because all translated bindings will be checked in every change detection cycle, even if translation doesn't happen. This can be worked around by using the OnPush change detection strategy. Prioritizes performance. Since the translation happens in build, the translated strings will be hard-coded into the target templates.
Does not require reloading for translation. Requires reloading for translation, on the premise that translation requests are rare.
Increases bundle size due to the additional bindings and the translation library. Internationalization doesn't affect the bundle size.
All translation strings have to be shipped to the user, even if they aren't needed. However, lazy-loaded modules can have their own translation files. Translations are done in build, so the client browser only gets what is necessary for the requested translation.
Translation files are very portable, readable and easy to create during development. They can be created gradually as the application grows, and also easily refactored. Managing translation files is so complex that a translation pipeline has to be defined (watch 6:35-10:15, read). The main problem is that the translation files have to be done from scratch every time that the app is changed. In this process, previous translations can only be reused by slowly copy-pasting the previously translated strings.
Translating contents dynamically is trivial, being the most common approach to translation with this library. Translating contents dynamically is complex.
Dynamically translated contents (which are extremely frequent with ngx-translate) are hard to track for SE's. The clean URL browsing and static translations strongly benefit SEO.

These were my main references:

I feel like there are so many big trade-offs here that it's really hard to choose...

Please feel free to improve this comparison!

Ardeliaardelis answered 12/1, 2023 at 15:25 Comment(0)
T
1

There is a quite complete comparison between Transloco, Angular-I18n and Ngx-translate in Transloco docs:

https://jsverse.github.io/transloco/

Terrazas answered 24/8, 2019 at 21:10 Comment(4)
the link is deadScrimshaw
This link works: netbasal.gitbook.io/transloco/comparison-to-other-librariesHyperbolize
No sadly not anymore.Bellyache
we have a new doc site now at: ngneat.github.io/translocoTerrazas

© 2022 - 2024 — McMap. All rights reserved.