Seems the CultureTypes.SpecificCultures
and CultureTypes.AllCultures
are related to Windows or service packs
. For more details, you can check this thread: Why does CultureInfo.GetCultures(CultureTypes.SpecificCultures) return different sets of cultures on different computers
And my suggestion is we should Custom CultureInfo, then the web app can be used for global users.
Here is the workaround for you.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
namespace BlazorApp3
{
public class CustomCulture
{
public string Name { get; set; }
public string EnglishName { get; set; }
public string NativeName { get; set; }
public DateTimeFormatInfo DateTimeFormat { get; set; }
public NumberFormatInfo NumberFormat { get; set; }
public CustomCulture(string name, string englishName, string nativeName)
{
Name = name;
EnglishName = englishName;
NativeName = nativeName;
DateTimeFormat = new DateTimeFormatInfo
{
ShortDatePattern = "dd/MM/yyyy",
LongDatePattern = "dddd, dd MMMM yyyy",
ShortTimePattern = "HH:mm",
LongTimePattern = "HH:mm:ss",
FullDateTimePattern = "dddd, dd MMMM yyyy HH:mm:ss"
};
NumberFormat = new NumberFormatInfo
{
CurrencySymbol = "KD",
CurrencyDecimalDigits = 3,
NumberDecimalDigits = 3
};
}
}
public static class CustomCultureInfo
{
private static readonly List<CustomCulture> CustomCultures = new List<CustomCulture>();
public static void RegisterCustomCulture()
{
var arKWCulture = new CustomCulture("ar-KW", "ar (KW)", "العربية (الكويت)");
CustomCultures.Add(arKWCulture);
}
public static IEnumerable<CustomCulture> GetAllCultures()
{
var specificCultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures)
.Select(c => new CustomCulture(c.Name, c.EnglishName, c.NativeName));
return specificCultures.Concat(CustomCultures).OrderBy(culture => culture.Name);
}
}
}
Register it.
using BlazorApp3;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
CustomCultureInfo.RegisterCustomCulture();
await builder.Build().RunAsync();
![enter image description here](https://cdn.statically.io/img/i.sstatic.net/oTKOK73A.png)