bitplatform: `BitDatePicker` issue in blazor server in OS that have wrong culture info with `GregorianCalendar` as default calendar for `fa-IR`

Describe the bug I set the culture info in startup.configure as follows:

var cultureInfo = new CultureInfo("fa-IR");
CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;
CultureInfo.CurrentCulture = cultureInfo;
CultureInfo.CurrentUICulture= cultureInfo;

However, the date picker shell will also be AD as follows, Only the names of the Gregorian months are shown in Persian.:

Untitled

The problem still persists even if the culture is set as follows in date picker:

<BitDatePicker @bind-Value="LetterModel.AtfPyroDate" Style="width: 300px" AllowTextInput="true" FormatDate="yyyy/MM/dd" GoToToday="امروز" Culture="@(new System.Globalization.CultureInfo("fa-IR"))"></BitDatePicker>

Now, if the Windows calendar is set to Hijri, this problem will be solved as follows:

Untitled

I also tried to customize the names of the months as shown below, but this time I did not succeed.

var cultureInfo = CultureInfo.CreateSpecificCulture("fa-IR");
cultureInfo.DateTimeFormat.MonthNames = new[] { "فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند", "" };

The problem is that in Windows 7 or other operating systems, it may not be possible to set the calendar to Hijri. How should we set the culture info so that the date picker shell is displayed in Persian in any case?

Expected behavior It is better not to follow the system culture by setting the date picker culture anymore.

Bit Blazor client

Bit nuget package’s version. 11.0.0 Blazor Server or Blazor Web Assembly or both? Blazor Server Which browser? Chrome Version 102.0.5005.63 (Official Build) (64-bit) Which blazor version? blazor 6

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 35 (20 by maintainers)

Commits related to this issue

Most upvoted comments

Dear @msynk @ysmoradi @maryamhdr, Congratulations! The problem has been resolved definitely. Thank you so much,

Best regards.

I ran your sample and it works like a chart. It seems that there is something OS-dependent is causing the issue Could you please run your sample in Clean Windows 10 in Virtual Machine or elsewhere? We can test Windows Server / Linux / Windows 7 after that. Plus provide me cultureData values in your current setup as followings: image This is your sample repo working totally fine on Windows 10 It seems that you’ve made it better by using fonts (Looks better than my sample) image

Thank you and congratulations. https://github.com/bitfoundation/bit-components-playground/tree/master/src/client/Pages/Issues/2188 works for me very well, but it only works for WebAssembly, and unfortunately it doesn’t work for BlazorServer. It seems that the reflection has been useful, but probably some changes should be made for BlazorServer.

I updated https://github.com/Kamalifar/TestBitComponentDatePicker based on “Bit.BlazorUI” package, however, the result is the same as before, but, If I create a new WebAssembly project and copy your code into it, it works correctly.

Please use latest version of “Bit.BlazorUI” package, not “Bit.Client.Web.BlazorUI”. And could you please let me know if https://github.com/bitfoundation/bit-components-playground/tree/master/src/client/Pages/Issues/2188 Works for you by cloning and running that repo Thanks in advance

The pre-release has been published. Please give it a try and give feedback.

In the new pre-release we’re using CultureInfo.DateTimeInfo.Calendar which is writable No need to change the default calendar anymore.

I’m afraid we can’t truly test this because this needs an OS which problem exists in there and we don’t have such an OS installed. And believe me or not, this is not BitDatePicker’s issue, but we’ll merge any PR you make if you wanna put more effort into this

It has some differences. Your default calendar is GreorianCalendar, mine is PersianCalendar That’s the issue

It’s my cultureData value in my current setup: Untitled This is exactly like your value.

This is very strange. Why the Blazor WebAssembly is working properly, but Blazor Server is not on my OS? However, I try to check this sample on another OS and I will announce the result here.

Thanks in advance, Best regards.

Thank you so much for all you have done. I used your code and the result is the same as before, as you can see in the picture. Untitled

Source code: https://github.com/Kamalifar/TestBitComponentDatePicker/blob/master/Pages/TestCultureInfoHelper.razor

Although today’s date is selected, which means the 9th day of July, it displays the calendar of Mehr 2022, which means that only the month array mapping is done and the main date picker of the Gregorian calendar remains. July is the seventh month of the year and Mehr is the seventh month of the Shamsi year. Please, first change the server calendar to Gregorian and then run the project. If the server calendar is changed while running, then the problem will not be seen.

Regards.

I was able to achieve followings

image

Source code:

https://github.com/bitfoundation/bit-components-playground/tree/issue-2188

There is an issue with CultureInfo.TextInfo.IsRightToLeft property which needs more investigation

You’ve been invited to the Microsoft teams. Give it a try! @Kamalifar

Dear @maryamhdr,

Thanks for your support and explanation. I’d like to use the BitDatePicker widely in my projects, So my email address is kamalifar@chmail.ir.

Best Regards, Ali Kamalifar

@Kamalifar Thanks a lot for contributing and submitting such detailed and clear issues. If you want to use the BitPlatform products widely in your projects, we can give you priority support for free, so in case you have an issue, you can contact the BitPlatform development team at Microsoft Teams quickly and get your answer ASAP. If you would like to have this support plan, let us know and send us your contact info (email address and full name)

@Kamalifar thanks a lot for providing the repo. I’ve cloned your test repo and ran it on both my laptop and PC. the component works fine on both of them without changing anything on the OS Region settings. I think we need to investigate it a little bit more. one of my colleagues will contact you soon 😊