Angular 5 - manually importing locale doesnt work


#1

Since angular 5 there has been a “breaking change” to importing additional locales:

By default Angular now only contains locale data for the language en-US, if you set the value of LOCALE_ID to another locale, you will have to import new locale data for this language because we don’t use the intl API anymore.

Before angular 5, just having these 2 lines was enough to use for example Date filter with custom locale:

import { LOCALE_ID } from '@angular/core';
{ provide: LOCALE_ID, useValue: 'de-CH' }

but now as we see in docs:
https://angular.io/guide/i18n#i18n-pipes

By default, Angular only contains locale data for en-US. If you set the value of LOCALE_ID to another locale, you must import locale data for that new locale. The CLI imports the locale data for you when you use the parameter --locale with ng serve and ng build.

If you want to import locale data for other languages, you can do it manually:

import { registerLocaleData } from '@angular/common';
import localeFr from '@angular/common/locales/fr';

// the second parameter 'fr' is optional
registerLocaleData(localeFr, 'fr');

But if i do it manually it gives an error:

System.err: SyntaxError: Unexpected token export
System.err: File: "file:///data/data/com.example.app/files/app/tns_modul
es/@angular/common/locales/fr.js, line: 10, column: 0

Is there anything to do?


#2

Hey guys, We have the same exact issue with this.
This is a huge blocking issue for us since we want to release our app very soon!

Looking forward hearing from you guys.


#3

Same here. Hope you have a solution soon.


#4

I created an issue on gitlab:
https://github.com/NativeScript/nativescript-angular/issues/1147


#5

hi, @Pete.K could you weigh in here please? Also pinging the team


#6

Hey all! The new localizations APIs in Angular 5 are not supported in NativeScript yet. We will be working on that for the one of the next minor versions. You can follow the progress in this issue in github - https://github.com/NativeScript/nativescript-angular/issues/1133.