Skip to content

Instantly share code, notes, and snippets.

@rightonhana
Last active October 3, 2021 04:11
Show Gist options
  • Select an option

  • Save rightonhana/080273095c42c9bd4d430939e31cefb4 to your computer and use it in GitHub Desktop.

Select an option

Save rightonhana/080273095c42c9bd4d430939e31cefb4 to your computer and use it in GitHub Desktop.
Internationalization(i18n) comparison for Angular.

Internationalization(i18n) comparison for Angular (AUG 2021)

TLDR

Tools JSON support Implementation Support for services, pipes, events and atributes Update frequently Opened issues Support other frameworks Demo
Built-in i18n no Complex services, pipes, events, and atributes yes ~ 2,000 no localize demo
ngx-translate yes Simple services, pipes, and events no ~ 400 no ngx-translate demo
angular-i18next yes Simple services, pipes, and events yes ~ 5 yes i18next demo

Angular i18n solution

Angular has its built-in solution for internationalization called localize. The solution is in the angular repository.

Pros:

  • Good documentation.
  • It has support for UNICODE CLDR.
  • It has a tool to extract strings into translation files.
  • It has an option to build an application for a given language.
  • Support for Ahead-of-Time compilation.
  • It can provide context for translations by adding meaning and descriptions.
  • It can mark HTML attributes for translation. For example:
<!-- You can use `i18n-attribute` in which `attribute` is the attribute to translate. -->
<img [src]="logo" i18n-title title="Angular logo" />
  • It can mix pluralization and alternate text messages. Different languages have different pluralization rules and grammatical constructions that make it difficult to get a correct translation and with the Angular built-in i18n module, it's a little easier.

Cons:

  • It's very complex.
  • There is no easy way to write a custom translation loader.
  • The tool for extracting strings into translation files only works with XML.
  • Does not support the latest version of Ionic.
  • It has around 2,000 issues opened.

Demo: The only live demo that I found it's weird but you can check it on StackBlitz.

ngx-translate

Ngx-translate is a third-party internationalization library for Angular that has been around for nearly four years now. It's modular and gives you services, directives, and pipes to handle dynamic or static content. It also supports Ionic applications. Here is the repo.

Pros:

  • It was created to overcome problems with the Angular built-in i18n module.
  • Good documentation.
  • Fast and simple integration process.
  • Support for Ahead-of-Time compilation (the last versions of Angular comes with AOT compile for default).
  • Translation files are stored in JSON format that makes them easier to work with and it's lightweight.
  • Translations can be performed by using a service, a pipe, or a directive.
  • Has support for event listeners to, for example, handle the language change.
  • Supports HTML markup inside translation messages.
  • It gives you the ability to define missing translation handlers.
  • It has several plugins that make your life easier.

Cons:

  • It was designed as a temporary solution for the Angular built-in i18n module, so probably in the future, the built-in module will supersede it.
  • The creator of ngx-translate joined the Angular team and he's working on the built-in i18n support now. The last library update was a year ago and probably may not be maintained anymore.
  • It has around 400 issues opened.

Demo: There is a live demo in StackBlitz with two languages. You can check it here.

i18next

I18next is a general internationalization-framework for Javascript. It supports both pure JS and framework-powered applications. It has implementations in several front-end and back-end frameworks and libraries such as Angular, React, Vue, .Net, etc. It also has an implementation for Android and iOS. You can check Angular implementation here.

Pros:

  • Good documentation.
  • It has support for multiple formats.
  • It can detect user language.
  • It has various translation loaders (you can load data from a file or provide them directly as a JSON object).
  • Translations can be performed by using a service, a pipe, or a directive.
  • It has plugins and utils for frameworks and languages such as Angular, React, Vue, .Net, PHP, Rails, and so on. You can check the utils here and the supported frameworks here.
  • You can perform translations, pluralization, and complex formatting with the same functions. The API is the same.
  • It has implementations for Android and iOS.
  • It has less than 10 issues opened.

Cons:

  • It's not strictly designed specifically for Angular.
  • Size (tree-shakeable).

Demo: You can find a live demo here with only two languages.

Summary

Tools License Last update Weekly Downloads Issues Size
Built-in i18n MIT 5 days ago 386,942 1,739 3.7kB
ngx-translate MIT A year ago 408,851 373 14.4kB
i18next and angular-i18next MIT and MIT 20 days ago and 3 month ago 1,436,455 and 6,879 4 and 1 43kB and 8.2kB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment