Abp: How to set the default culture in "BackendAdminApp.Host"?

Created on 26 Dec 2019  ·  16Comments  ·  Source: abpframework/abp

In the "BackendAdminApp.Host" project's BackendAdminAppHostModule.cs I add the following code force to set all the DefaultCultureName to the culture I needed.But it didn't work, the culture is also "en",and I found the culture resource I added can work if the key is not the same as others.
And also I tryed to add the cookie in the start page like the code below,because I found the "/Abp/Languages/Switch" do the same thing.But it did'nt work also.

cs Configure<AbpLocalizationOptions>(options => { options.Languages.Add(new LanguageInfo("en", "en", "English")); options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文")); foreach (var key in options.Resources.Keys) { options.Resources[key].DefaultCultureName = "zh-Hans"; } });
```cs

public void OnGet()
{
string cookieValue = CookieRequestCultureProvider.MakeCookieValue(new RequestCulture("zh-Hans", "zh-Hans"));

        Response.Cookies.Append(CookieRequestCultureProvider.DefaultCookieName, cookieValue, new CookieOptions
        {
            Expires = DateTime.Now.AddYears(2)
        });
    }
question

Most helpful comment

Should be inside the Settings section.

json { "Settings": { "Abp.Localization.DefaultLanguage": "zh-Hans" } }

All 16 comments

Set Abp.Localization.DefaultLanguage setting (as constant: LocalizationSettingNames.DefaultLanguage) to zh-Hans. See https://docs.abp.io/en/abp/latest/Settings#setting-values-in-the-application-configuration to simply set it in the appsettings.json

I added like this way but it does not work, is it right?
setting

Should be inside the Settings section.

json { "Settings": { "Abp.Localization.DefaultLanguage": "zh-Hans" } }

when I added the settings in AuthServer.Host and BackendAdminApp.Host ,the AuthServer.Host's default language changed,but the BackendAdminApp.Host not.Even though I added the settings in "IdentityService.Host" and "BackendAdminAppGateway.Host" it not change also.

I stills think this is an issue,even I set the "Abp.Localization.DefaultLanguage" in the table “AbpSettings” to "zh-Hans" and when I visited "http://localhost:51954/Abp/ApplicationConfigurationScript" the settings show the default language is 'zh-Hans' but the words also show as english.Please see the screenshot below:
1
2
3

Clear all cookies and try again. Also, be sure that the default language setting was not set for the user in the database.

The reason is your default cultrue is "zh-CN", not "zh-Hans".

I write a class library that can map these language codes.

https://github.com/maliming/Owl.Abp.CultureMap
c# var maps = new Dictionary<string, string> { {"zh", "zh-Hans"}, {"zh-CN", "zh-Hans"}, {"zh-Hant", "zh-Hans"}, {"zh-TW", "zh-Hans"} }

Should be inside the Settings section.

{
  "Settings": {
    "Abp.Localization.DefaultLanguage": "zh-Hans"
  }
}

no effect

I stills think this is an issue,even I set the "Abp.Localization.DefaultLanguage" in the table “AbpSettings” to "zh-Hans" and when I visited "http://localhost:51954/Abp/ApplicationConfigurationScript" the settings show the default language is 'zh-Hans' but the words also show as english.Please see the screenshot below:
1
2
3

Have you solved it?

@abllyboy do you fixed it? I can not make it works

In the "BackendAdminApp.Host" project's BackendAdminAppHostModule.cs I add the following code force to set all the DefaultCultureName to the culture I needed.But it didn't work, the culture is also "en",and I found the culture resource I added can work if the key is not the same as others.
And also I tryed to add the cookie in the start page like the code below,because I found the "/Abp/Languages/Switch" do the same thing.But it did'nt work also.

  Configure<AbpLocalizationOptions>(options =>
           {
                options.Languages.Add(new LanguageInfo("en", "en", "English"));
                options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文"));
                foreach (var key in options.Resources.Keys)
                {
                    options.Resources[key].DefaultCultureName = "zh-Hans";
                }
           });
 public void OnGet()
       {
           string cookieValue = CookieRequestCultureProvider.MakeCookieValue(new RequestCulture("zh-Hans", "zh-Hans"));

           Response.Cookies.Append(CookieRequestCultureProvider.DefaultCookieName, cookieValue, new CookieOptions
           {
               Expires = DateTime.Now.AddYears(2)
           });
       }

I got it.
just modify in GateWay,Not in WebSite.And add app.UseAbpRequestLocalization(); into GatewayHostModule.@xyfy

Should be inside the Settings section.

{
  "Settings": {
    "Abp.Localization.DefaultLanguage": "zh-Hans"
  }
}

It worked except in Identity Moudule,for example,when I create a user with duplicate UserName,the err msg is still in English.

Should be inside the Settings section.

{
  "Settings": {
    "Abp.Localization.DefaultLanguage": "zh-Hans"
  }
}

It worked except in Identity Moudule,for example,when I create a user with duplicate UserName,the err msg is still in English.

In the "BackendAdminApp.Host" project's BackendAdminAppHostModule.cs I add the following code force to set all the DefaultCultureName to the culture I needed.But it didn't work, the culture is also "en",and I found the culture resource I added can work if the key is not the same as others.
And also I tryed to add the cookie in the start page like the code below,because I found the "/Abp/Languages/Switch" do the same thing.But it did'nt work also.

  Configure<AbpLocalizationOptions>(options =>
           {
                options.Languages.Add(new LanguageInfo("en", "en", "English"));
                options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文"));
                foreach (var key in options.Resources.Keys)
                {
                    options.Resources[key].DefaultCultureName = "zh-Hans";
                }
           });
 public void OnGet()
       {
           string cookieValue = CookieRequestCultureProvider.MakeCookieValue(new RequestCulture("zh-Hans", "zh-Hans"));

           Response.Cookies.Append(CookieRequestCultureProvider.DefaultCookieName, cookieValue, new CookieOptions
           {
               Expires = DateTime.Now.AddYears(2)
           });
       }

I got it.
just modify in GateWay,Not in WebSite.And add app.UseAbpRequestLocalization(); into GatewayHostModule.@xyfy

@journey191

@x2009again Hi,
My project type is Application(Angular),not Module.There is no GatewayHostModule in my project.
I reuqest the API /api/abp/application-configuration and the response show that currentCulture is already Chinese.
image

But the Excetion Message is still in English.For example,client request get "Identity.DuplicateUserName",not expected "用户名 '{0}' 已存在."

@x2009again Hi,
My project type is Application(Angular),not Module.There is no GatewayHostModule in my project.
I reuqest the API /api/abp/application-configuration and the response show that currentCulture is already Chinese.
image

But the Excetion Message is still in English.For example,client request get "Identity.DuplicateUserName",not expected "用户名 '{0}' 已存在."

UI should access api through gateway,not directly access the api.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wocar picture wocar  ·  3Comments

vfabregat picture vfabregat  ·  3Comments

ugurozturk picture ugurozturk  ·  3Comments

hikalkan picture hikalkan  ·  3Comments

SmallShrimp picture SmallShrimp  ·  3Comments