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

Unintended localization for DateTime strings #56053

Closed
1 task done
danzhu54 opened this issue Jun 3, 2024 · 3 comments
Closed
1 task done

Unintended localization for DateTime strings #56053

danzhu54 opened this issue Jun 3, 2024 · 3 comments
Labels
area-blazor Includes: Blazor, Razor Components Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update.

Comments

@danzhu54
Copy link

danzhu54 commented Jun 3, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

We're seeing unintentional localization occuring on the marketing site. On the Blazor project, we do not have localization enabled.

The code that is causing this issue is here:
show.LocalScheduledStartTime?.ToString("hh:mmtt")

It appears that converting a DateTime to a string is automatically also taking browser locale into consideration even though we do not have it enabled in our Program.cs file

Expected Behavior

The DateTime toString method should not automatically convert DateTimes to the browser locale when localization is not enabled on the project.

Steps To Reproduce

Repo steps:

  1. Set default browser language to Japanese
  2. Navigate to https://dotnet.microsoft.com/live
  3. Scroll to the bottom of the page and select English (United States) in the footer dropdown
  4. Observe the page is still displaying the dates and times in Japanese

Exceptions (if any)

No response

.NET Version

8.0

Anything else?

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Jun 3, 2024
@javiercn
Copy link
Member

javiercn commented Jun 4, 2024

@danzhu54 thanks for contacting us.

I think that if you have a different locale you need to set up that locale when the webassembly process starts in Program.cs on Thread.CurrentCulture and Thread.CurrentUICulture to whatever language you want to use.

@javiercn javiercn added the Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. label Jun 4, 2024
@danzhu54
Copy link
Author

danzhu54 commented Jun 6, 2024

Thanks @javiercn that resolved the issue for us. However, I feel like it's not intutive to require setting this value by default. This behavior creates an inconsistent experience for a user visiting for example an english only site by having a mixture of english text and DateTime elements rendered into their browser locale.

@dotnet-policy-service dotnet-policy-service bot added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Jun 6, 2024
@javiercn
Copy link
Member

javiercn commented Jun 7, 2024

@danzhu54 thanks for the additional details.

We have an item on the backlog to flow the culture from the server to webassembly and use that.

#26941

Closing this as a dupe of it.

@javiercn javiercn closed this as completed Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update.
Projects
None yet
Development

No branches or pull requests

2 participants