Missing locale data for the locale "XXX" with angular

AngularAngular I18n

Angular Problem Overview


I currently define "LOCALE_ID" on "en-US" this way:

@NgModule({
    providers: [{ provide: LOCALE_ID, useValue: "en-US" }, ...],
    imports: [...],
    bootstrap: [...]
})

and it works pretty well. However, in order to test how dates look like in French, I replaced "en-US" by "fr-FR" and then I got the error:

> Missing locale data for the locale "fr-FR".

I did some researches and I didn't find anything related to that. Are the locale for french included in the default package? Is it a different package? Do I have to create them by myself?

Angular Solutions


Solution 1 - Angular

In file app.module.ts

...
import { NgModule, LOCALE_ID } from '@angular/core';
import { registerLocaleData } from '@angular/common';
import localeFr from '@angular/common/locales/fr';
registerLocaleData(localeFr);


@NgModule({
  imports: [...],
  declarations: [...],
  bootstrap: [...],
  providers: [
    { provide: LOCALE_ID, useValue: 'fr-FR'},
  ]
})
export class AppModule {}

(source: https://next.angular.io/guide/i18n)

and in your template (*.component.html)

DATE in FRENCH: {{ dateEvent | date: 'longDate'}}

Result:

DATE in FRENCH: 25 mars 2018

(source: https://angular.io/api/common/DatePipe)

Solution 2 - Angular

Thanks @Alan, you just forgot this : import { registerLocaleData } from '@angular/common';

Complete code :

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

@NgModule({
  imports: [...],
  declarations: [...],
  bootstrap: [...],
  providers: [
    { provide: LOCALE_ID, useValue: 'fr-FR'},
  ]
})
export class AppModule {}

Solution 3 - Angular

please take a look at https://github.com/angular/angular-cli/issues/6683

this might be your case

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionssougnezView Question on Stackoverflow
Solution 1 - AngularAlanView Answer on Stackoverflow
Solution 2 - AngularAdrien VView Answer on Stackoverflow
Solution 3 - AngularFadi Abo MsalamView Answer on Stackoverflow