in blazor ui version 2.24.1 I use this code in program.cs for globalization:
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.Services.AddTransient(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddTelerikBlazor();
// register a custom localizer for the Telerik components, after registering the Telerik services
builder.Services.AddSingleton(typeof(ITelerikStringLocalizer), typeof(SampleResxLocalizer));
var host = builder.Build();
await SetCultureAsync(host);
await host.RunAsync();
}
private static async Task SetCultureAsync(WebAssemblyHost host)
{
var jsRuntime = host.Services.GetRequiredService<IJSRuntime>();
var cultureName =await jsRuntime.InvokeAsync<string>("blazorCulture.get");
if (cultureName != null)
{
var culture = new CultureInfo("fa-IR");
DateTimeFormatInfo info = culture.DateTimeFormat;
info.AbbreviatedDayNames = new string[] { "ی", "د", "س", "چ", "پ", "ج", "ش" };
info.DayNames = new string[] { "یکشنبه", "دوشنبه", "ﺳﻪشنبه", "چهارشنبه", "پنجشنبه", "جمعه", "شنبه" };
info.AbbreviatedMonthNames = new string[] { "فروردین", "ارديبهشت", "خرداد", "تير", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند", "" };
info.MonthNames = new string[] { "فروردین", "ارديبهشت", "خرداد", "تير", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند", "" };
info.AMDesignator = "ق.ظ";
info.PMDesignator = "ب.ظ";
info.ShortDatePattern = "yyyy/MM/dd";
info.FirstDayOfWeek = DayOfWeek.Saturday;
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;
}
}
when use TelerikDatePicker , id dosenot work properly. the code of my component in here:
<div class="demo-section k-form k-form-vertical">
<div class="k-form-field">
<label for="travel-date" class="k-label k-form-label">Travel Date</label>
<div class="k-form-field-wrap">
<TelerikDatePicker Min="@Min" Max="@Max" @bind-Value="@selectedDate" Id="travel-date"></TelerikDatePicker>
</div>
</div>
<div class="k-form-field">
<p>The selected travel date is: <strong>@selectedDate?.ToShortDateString()</strong></p>
<p>The selected travel date is: <strong>@selectedDate?.ToString()</strong></p>
<p>The selected travel date is: <strong>@selectedDate?.ToUniversalTime()</strong></p>
<p>The selected travel date is: <strong>@selectedDate?.ToLongDateString()</strong></p>
</div>
</div>
@code {
public DateTime Max = new DateTime(2050, 12, 31);
public DateTime Min = new DateTime(1950, 1, 1);
private DateTime? selectedDate=DateTime.Now;
}
when click the datepicker the date is not correct :