abp icon indicating copy to clipboard operation
abp copied to clipboard

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

Open abllyboy opened this issue 6 years ago • 17 comments

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)
           });
       }

abllyboy avatar Dec 26 '19 05:12 abllyboy

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

hikalkan avatar Dec 29 '19 10:12 hikalkan

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

abllyboy avatar Dec 29 '19 15:12 abllyboy

Should be inside the Settings section.

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

hikalkan avatar Dec 29 '19 16:12 hikalkan

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.

abllyboy avatar Dec 30 '19 01:12 abllyboy

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

abllyboy avatar Jan 03 '20 07:01 abllyboy

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

hikalkan avatar Jan 05 '20 18:01 hikalkan

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

mentianyi avatar Mar 29 '20 22:03 mentianyi

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

https://github.com/maliming/Owl.Abp.CultureMap

var maps = new Dictionary<string, string>
{
	{"zh", "zh-Hans"},
	{"zh-CN", "zh-Hans"},
	{"zh-Hant", "zh-Hans"},
	{"zh-TW", "zh-Hans"}
}

maliming avatar Mar 30 '20 00:03 maliming

Should be inside the Settings section.

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

no effect

x2009again avatar Apr 27 '20 09:04 x2009again

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?

x2009again avatar Apr 27 '20 09:04 x2009again

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

xyfy avatar Jun 04 '20 01:06 xyfy

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

x2009again avatar Jun 07 '20 14:06 x2009again

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.

journey191 avatar Nov 12 '20 17:11 journey191

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 avatar Nov 13 '20 01:11 x2009again

@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}' 已存在."

journey191 avatar Nov 13 '20 01:11 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}' 已存在."

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

x2009again avatar Nov 13 '20 03:11 x2009again

I have the same problem. Is there a solution?

344089386 avatar Nov 13 '23 03:11 344089386