Open Closed

How to set default language as Chinese in Blazor Server App? #2504


User avatar
0
zhongfang created

My clients want to look Chinese UI, while they touch my web application.

How to do ?

  • ABP Framework version: v5.1.1
  • UI type: Blazor
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no

2 Answer(s)
  • User Avatar
    0
    EngincanV created
    Support Team .NET Developer

    Hi @zhongfang, you can update your UseAbpRequestLocalization middleware (under your *.HttpApiHostModule) as follows:

    //list your supported cultures
    var supportedCultures = new[]
    {
        new CultureInfo("zh-Hans"),
        new CultureInfo("cs"),
        new CultureInfo("en"),
        new CultureInfo("tr"),
        //...
    };
    
    app.UseAbpRequestLocalization(options =>
    {
        options.DefaultRequestCulture = new RequestCulture("zh-Hans"); //set default as zh-Hans
        options.SupportedCultures = supportedCultures;
        options.SupportedUICultures = supportedCultures;
        options.RequestCultureProviders = new List<IRequestCultureProvider>
        {
            // there are three culture providers
            new QueryStringRequestCultureProvider(),
            new CookieRequestCultureProvider(),
            new AcceptLanguageHeaderRequestCultureProvider()
        };
    });
    

    https://github.com/abpframework/abp/issues/2775 https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization?view=aspnetcore-6.0#localization-middleware

  • User Avatar
    0
    zhongfang created

    I found many result articles by search Google and Baidu. And I tried out them. But I failed.

    Now, you resolved my question.

    Thank you.

    Maybe you can add above content to UserGuide.

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11