ddd
ddd

Reputation: 101

Angular ngx translate missing locale data for the locale

I have an angular application that uses ngx translate. So I mi up a pipe that format a date according to the language

@Pipe({
  name: 'localizedDate',
  pure: false
})
export class LocalizedDatePipe implements PipeTransform {
    
  constructor(private translateService: TranslateService) {
  }
    
  transform(value: any, pattern: string = 'shortDate'): any {
    const datePipe: DatePipe = new DatePipe(this.translateService.currentLang);
    return datePipe.transform(value, pattern);
  }
}

In local I am no problem but when I build with the production mode I encounter the following problem:

I get the following error:

Error: InvalidPipeArgument: 'Missing locale data for the locale "fr". ' for pipe 't'

Example of a date I get from my api: 2021-06-10T12:12:29.787428+00:00

Upvotes: 1

Views: 1212

Answers (1)

Suresh Nagar
Suresh Nagar

Reputation: 1199

This is not ngx translate issue, you need register locale data with Angular before using date or currency pipe etc for formatting.

e.g. for french

    import localeFr from '@angular/common/locales/fr';
    import localeFrExtra from '@angular/common/locales/extra/fr';

...............    
    registerLocaleData(localeFr, 'fr', localeFrExtra);
    registerLocaleData(localeFr, 'fr-FR', localeFrExtra);

Upvotes: 2

Related Questions