Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 10 - register custom locale

Due to Angular update, I have problem with locales.

For now:

import localePl from '@angular/common/locales/pl';
registerLocaleData(localePl);

It's working but causes an error:

WARNING in app.module.ts depends on @angular/common/locales/pl. CommonJS or AMD dependencies can cause optimization bailouts.

Where does it work?

  1. I provide LOCALE_ID with value pl-PL
  2. And use DatePipe in HTML. (variable | date) - variable is equal to new Date()

Tested ways:

1)

import localePl from '@angular/common/locales/global/pl'; registerLocaleData(localePl, 'pl-PL');

Error:

'Cannot read property '0' of undefined' for pipe

In code: variable | date

Where variable is equal to new Date()

2) If I completely remove registerLocaleData

Error:

Missing locale data for the locale "pl-PL".' for pipe 'DatePipe'

like image 717
Thomas Banderas Avatar asked Jun 29 '20 17:06

Thomas Banderas


1 Answers

I had same issues, to resolve that I, in my app.module:

add

import '@angular/common/locales/global/pl

remove

import localePl from '@angular/common/locales/pl';

and remove "registerLocaleData" function, kept the LOCALE_ID provider setting.

I hope works for you too.

like image 122
Benjamim Goulart Bessa Avatar answered Nov 15 '22 19:11

Benjamim Goulart Bessa