Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 6 i18n runtime translation support

I've read i18n runtime support is coming in angular 6, but cant find anything in rc3. Is it postponed or not yet documented? The i18n documentation still states than one have to build a separate build for each language.

https://github.com/ngx-translate is an alternative but i don't know how long this will be supported or if the support in Angular 6 will be totally different. Migrating later then will include rewrite of all i18n instances in the code and create new translation files. I have room to wait a little in my project but not forever.

Not been able to find anything on how the new i18n support in Angular 6 will be, except that it is coming.

like image 357
RockBop Avatar asked Apr 10 '18 09:04

RockBop


People also ask

What is i18n translation?

Internationalization (sometimes shortened to "I18N , meaning "I - eighteen letters -N") is the process of planning and implementing products and services so that they can easily be adapted to specific local languages and cultures, a process called localization .

Does AngularJS support internalization?

AngularJS supports inbuilt internationalization for three types of filters currency, date and numbers. We only need to incorporate corresponding js according to locale of the country. By default it handles the locale of the browser.

What is locales in Angular?

Angular uses the Unicode locale identifier (Unicode locale ID) to find the correct locale data for internationalization of text strings. Unicode locale ID. A locale ID conforms to the Unicode Common Locale Data Repository (CLDR) core specification.


2 Answers

The author of ngx-translate, Olivier Combe, is working with Angular to upgrade their i18n offerings to offer runtime translation, along with numerous other upgrades. I believe this functionality is expected in Angular 7, but Combe has published a polyfill for earlier versions.

https://github.com/ngx-translate/i18n-polyfill

It is fairly simple to integrate with an existing Angular i18n setup, with only minimal legwork. I'd recommend using this over ngx-translate, as Angular i18n - while more complicated to work with - is significantly more feature-rich than ngx-translate.

See Combe's discussion of the differences here: https://github.com/ngx-translate/core/issues/495#issuecomment-291158036

like image 116
Greg J Preece Avatar answered Oct 26 '22 07:10

Greg J Preece


Based on a comment on https://github.com/angular/angular/issues/11405 and since we have to wait for Angular 8, I have created gist that shows how to use a helper component and a service for collecting translations.

This works only with JIT and only simple interpolations are supported.

https://gist.github.com/mohlendo/90c834f90bc084af2b869ca36a20712f

like image 44
mohlendo Avatar answered Oct 26 '22 05:10

mohlendo