4

I'm working on i18n in Angular 8 app. I have registered locale Hindi ('hi') using following code inside app.module.ts.

import { registerLocaleData } from '@angular/common';
import localeHi from '@angular/common/locales/hi';
import localeHiExtra from '@angular/common/locales/extra/hi';

registerLocaleData(localeHi, 'hi', localeHiExtra);

It changed the digits and month text inside which is as expected. But, when I use DatePipe on date inside a template, it just converted month name to Devanagari and didn't converted digits of date. Same is happening with DecimalPipe.

I even tried to specify locale manually to these pipes, but it didn't work. Why is it behaving differently with <mat-datepicker> and DatePipe? I'm doing something wrong or is it intended behaviour? Any help would be appreciated!

Gourav Pokharkar
  • 1,568
  • 1
  • 11
  • 33
  • Does this help: https://stackoverflow.com/questions/43323210/how-to-format-number-based-on-user-locale-in-angular-2 – jdaz Jul 09 '20 at 06:39
  • Thanks! But actually my issue is inconsistency in the behavior and not the workaround. I want it to be handled by Angular in consistent way but surprisingly it's not doing so. – Gourav Pokharkar Jul 10 '20 at 07:10

1 Answers1

2

While finding solution, I found that in Angular Material Datepicker, I'm using MomentDateAdapter. It's moment.js which has Devanagari digits included in its Hindi locale, but Angular doesn't have these digits.

That's why I'm not able to get Devanagari digits in other places. Though, I wish it could be consistent in all places.

Gourav Pokharkar
  • 1,568
  • 1
  • 11
  • 33