Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(Datepicker): Datepicker with Moment ignores locale #28263

Open
1 task done
mzeitz1902 opened this issue Dec 11, 2023 · 14 comments
Open
1 task done

bug(Datepicker): Datepicker with Moment ignores locale #28263

mzeitz1902 opened this issue Dec 11, 2023 · 14 comments
Labels
area: material/datepicker P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@mzeitz1902
Copy link

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

16

Description

Since updating to Angular 17, my mat-datepicker ignores my locale. Everything should be in German but instead it's all in English now.

Reproduction

StackBlitz link: https://components-issue-uudyxr.stackblitz.io
Steps to reproduce:

  1. Open the datepicker to select a date
  2. Select a year and a month

Expected Behavior

The months are displayed in German (screenshot taken from production environment that doesn't have the update to Angular 17 yet).

image
image

Actual Behavior

The months are displayed in English

image
image

Environment

  • Angular: 17.0.6
  • CDK/Material: 17.0.3
  • Browser(s): Chrome
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows 11
@mzeitz1902 mzeitz1902 added the needs triage This issue needs to be triaged by the team label Dec 11, 2023
@jahusa02
Copy link

jahusa02 commented Dec 13, 2023

We have the same problem.

Do you use the new ESbuild builder?

@mzeitz1902
Copy link
Author

Yes, we do

@jahusa02
Copy link

Yes, we do

I guess it's a Problem with that. Can't find the Issue Link rn but will provide it later. Since the ESBuild Builder, the default locale is always 'en_US'

@mzeitz1902
Copy link
Author

Okay, but can we fix that somehow or is it in fact a bug?

@jahusa02
Copy link

Didn't find a way yet. We reverted back to Webpack for the moment

@Sebi11
Copy link

Sebi11 commented Dec 21, 2023

Same issue here, with my newly migrated app to Angular 17, using the new Vite builder.

I cannot find the other issue you're talking about @jahusa02 but I'd be glad to read it as well in case I could provide a workaround!

EDIT: I ran a few tests. It seems the bug comes from Moment library in fact: the method moment.localeData(str) always return the same object (English locale). I tried moment.localeData('fr') directly in my main app which leads to the bug, and then the bug occurs in the Materiel Datepicker as well.

@mzeitz1902
Copy link
Author

So, do you guys think this bug will be adressed soon? I really don't want to go back to Angular 16 or the old builder.

@jahusa02
Copy link

Same issue here, with my newly migrated app to Angular 17, using the new Vite builder.

I cannot find the other issue you're talking about @jahusa02 but I'd be glad to read it as well in case I could provide a workaround!

EDIT: I ran a few tests. It seems the bug comes from Moment library in fact: the method moment.localeData(str)always return the same object (English locale). I triedmoment.localeData('fr')` directly in my main app which leads to the bug, and then the bug occurs in the Materiel Datepicker as well.

I can't find it anymore 😅 sorry.
Closest Issue I found is this one: angular/angular-cli#26409 (comment)

@mzeitz1902
Copy link
Author

Hmm I tried removing import '@angular/localize/init';. Didn't fix it though

@CodingMonkeyN
Copy link

You can use a workaround like:
import 'moment/locale/de';

This way the locales get compiled and work again.

@Michriko
Copy link

Michriko commented Jan 9, 2024

Had the same issue.
Also used the workaround @CodingMonkeyN suggested.

@mzeitz1902
Copy link
Author

Thank you @CodingMonkeyN ! This works :)

@andrewseguin andrewseguin added area: material/datepicker P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent and removed needs triage This issue needs to be triaged by the team labels Jan 29, 2024
@BenjaminBrodwolf
Copy link

Have the same issue but I don't understand this workaround.
Where I have to add this import 'moment/locale/de'; ?

@CodingMonkeyN
Copy link

You need to adjust your imports where you normally import Moment with the import specifying the wanted locales.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: material/datepicker P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

No branches or pull requests

7 participants