abpframework / abp

Open-source web application framework for ASP.NET Core! Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET. Provides the fundamental infrastructure, cross-cutting-concern implementations, startup templates, application modules, UI themes, tooling and documentation.
https://abp.io
GNU Lesser General Public License v3.0
12.72k stars 3.4k forks source link

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

Closed abllyboy closed 4 years ago

abllyboy commented 4 years ago

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)
            });
        }
hikalkan commented 4 years ago

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

abllyboy commented 4 years ago

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

hikalkan commented 4 years ago

Should be inside the Settings section.

{
  "Settings": {
    "Abp.Localization.DefaultLanguage": "zh-Hans"
  }
}
abllyboy commented 4 years ago

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 commented 4 years ago

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
hikalkan commented 4 years ago

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

mentianyi commented 4 years ago

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

maliming commented 4 years ago

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"}
}
x2009again commented 4 years ago

Should be inside the Settings section.

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

no effect

x2009again commented 4 years ago

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?

xyfy commented 4 years ago

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

x2009again commented 4 years ago

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 commented 3 years ago

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.

x2009again commented 3 years ago

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

journey191 commented 3 years ago

@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 commented 3 years ago

@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.

344089386 commented 9 months ago

I have the same problem. Is there a solution?