MudBlazor / MudBlazor

Blazor Component Library based on Material design with an emphasis on ease of use. Mainly written in C# with Javascript kept to a bare minimum it empowers .NET developers to easily debug it if needed.
http://mudblazor.com
MIT License
8.05k stars 1.27k forks source link

Use CurrentCulture, not CurrentUICulture, for dates etc. #5123

Open ArneMancofi opened 2 years ago

ArneMancofi commented 2 years ago

Bug type

Other

Component name

No response

What happened?

MudBlazor\Utilities\BindingConverters\Converters.cs uses CurrentUICulture for defining the default culture used for date and number conversion:

public static class Converters
{
    public static CultureInfo DefaultCulture = CultureInfo.CurrentUICulture;

It is my impression that CultureInfo.CurrentUICulture is only supposed to be used for ResourceManager related operations for fetching localized text, etc., cf. the CultureInfo.CurrentUICulture documentation.

Expected behavior

It seems to me that CultureInfo.CurrentCulture should be used instead, cf. the CultureInfo.CurrentCulture documentation:

The CultureInfo object that's returned by this property and its associated objects determine the default format for dates, times, numbers, currency values, the sorting order of text, casing conventions, and string comparisons.

Reproduction link

https://try.mudblazor.com/snippet/QkGQOClZSiDJVuvJ

Reproduction steps

Oftentimes, the two values of CultureInfo.CurrentUICulture and CultureInfo.CurrentCulture are identical, so the effect of using CultureInfo.CurrentUICulture may go unnoticed. However, sometimes they may differ, for instance if Windows applications should display English text, but dates and numbers should be formatted using, say, Danish, German or French culture.

Relevant log output

No response

Version (bug)

6.0.14

Version (working)

No response

What browsers are you seeing the problem on?

Chrome

On what operating system are you experiencing the issue?

Windows

Pull Request

Code of Conduct

Ksdmg commented 1 year ago

I'm now facing this issue as my company is using english windows but german date and number formats. Mudblazor is using a dot as decimal separator while it should use a comma.

Is there any easy workaround?

Here is an example of the issue we have with culture en-DE

image

<h1>Culture Example 1</h1>

<p>
    <b>CurrentCulture</b>: @CultureInfo.CurrentCulture
</p>

<h2>Rendered values</h2>

<ul>
    <li><b>Date</b>: @dt</li>
    <li><b>Number</b>: @number.ToString("N2")</li>
</ul>

<h2><code>&lt;input&gt;</code> elements that don't set a <code>type</code></h2>

<p>
    The following <code>&lt;input&gt;</code> elements use
    <code>CultureInfo.CurrentCulture</code>.
</p>

<ul>
    <li><label><b>Date:</b> <input @bind="dt" /></label></li>
    <li><label><b>Number:</b> <input @bind="number" /></label></li>
</ul>

<h2><code>&lt;input&gt;</code> elements that set a <code>type</code></h2>

<p>
    The following <code>&lt;input&gt;</code> elements use
    <code>CultureInfo.InvariantCulture</code>.
</p>

<ul>
    <li><label><b>Date:</b> <input type="date" @bind="dt" /></label></li>
    <li><label><b>Number:</b> <input type="number" @bind="number" /></label></li>
</ul>
<MudForm>
    <MudNumericField @bind-Value="number" />

</MudForm>

@code {
    private DateTime dt = DateTime.Now;
    private double number = 1999.69;
}