Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set the default language? #2775

Closed
majidbigdeli opened this issue Feb 6, 2020 · 7 comments
Closed

How to set the default language? #2775

majidbigdeli opened this issue Feb 6, 2020 · 7 comments

Comments

@majidbigdeli
Copy link

i use

"Settings": {
"Abp.Localization.DefaultLanguage": "cs"
}

in appsettings.json

but not working

@maliming
Copy link
Member

maliming commented Feb 7, 2020

The default language has lower priority than QueryStringRequestCultureProvider, CookieRequestCultureProvider, AcceptLanguageHeaderRequestCultureProvider.

see https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization?view=aspnetcore-3.1#localization-middleware

@johnnba
Copy link

johnnba commented Feb 7, 2020

Dear @majidbigdeli

 var defaultLanguage = context.ServiceProvider.GetService<ISettingDefinitionManager>().Get(LocalizationSettingNames.DefaultLanguage);
            defaultLanguage.DefaultValue = "zh-Hans";

if you set failed ,you can set it manually by the above code.

@majidbigdeli
Copy link
Author

@hello @johnnba

it is not working . Current Culture not changed

@yerayvm
Copy link

yerayvm commented Feb 9, 2020

@majidbigdeli you can try in Startup.cs inside ConfigureServices this code:

           CultureInfo[] supportedCultures = new[]
               {
                    new CultureInfo("cs"),
                    new CultureInfo("en")
                };

            services.Configure<RequestLocalizationOptions>(options =>
            {
                options.DefaultRequestCulture = new RequestCulture("cs");
                options.SupportedCultures = supportedCultures;
                options.SupportedUICultures = supportedCultures;
                options.RequestCultureProviders = new List<IRequestCultureProvider>
                {
                    new QueryStringRequestCultureProvider(),
                    new CookieRequestCultureProvider()
                };
            });
 

and then in your ---module.cs inside OnApplicationInitialization paste this code above app.UseMvcWithDefaultRouteAndArea(); :

app.UseRequestLocalization();

this worked for me!

@crybigsea
Copy link

@yerayvm Hi, I tried your way, it worked for me, thanks!
I modified the app.UseAbpRequestLocalization() in OnApplicationInitialization to the following code:

var supportedCultures = new[]
{
    new CultureInfo("cs"),
    new CultureInfo("en"),
};
app.UseAbpRequestLocalization(options =>
{
    options.DefaultRequestCulture = new RequestCulture("cs");
    options.SupportedCultures = supportedCultures;
    options.SupportedUICultures = supportedCultures;
    options.RequestCultureProviders = new List<IRequestCultureProvider>
    {
        new QueryStringRequestCultureProvider(),
        new CookieRequestCultureProvider()
    };
});

and thank you again!

@stale
Copy link

stale bot commented Jul 29, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the inactive label Jul 29, 2020
@stale stale bot closed this as completed Aug 5, 2020
@bodeg
Copy link

bodeg commented Apr 3, 2022

I tried @crybigsea suggestion
Set two supported languages: English and Hebrew, the default language is Hebrew.

Once I did it - I got the correct default language, but when I switch to the other language I still getting the default language texts.

Switching languages without that code works fine.
any idea?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants