Open Closed

How to set the default culture? #1651


User avatar
0
GregB created
  • ABP Framework version: v4.3.3
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no (Angular)
  • Exception message and stack trace: N/A
  • Steps to reproduce the issue:"

How do I set the default culture and UI culture of my Angular app?

I've configured my FooApiHostModule like so

private void ConfigureLocalization()
{
    Configure<AbpLocalizationOptions>(options =>
    {
        options.Languages.Clear();
        options.Languages.Add(new LanguageInfo("en-GB", "en-GB", "English"));
    });
}

I've duplicated the en.json localization file and renamed it en-GB, I've changed the Culture elemein in the top of that file like so

{
  "Culture": "en-GB",
  "Texts": {
    ...
  }
}

If I put a breakpoint in a controller action, and inspect System.Threading.Thread.CurrentThread.CurrentCulture and System.Threading.Thread.CurrentThread.CurrentUICulture they're both "en", not "en-GB".

How do I get my application to run in en-GB ?

I've also cahnged my Startup.Configure() method like so, but this doesn't fix it either.

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
    {
        app.InitializeApplication();

        app.UseRequestLocalization(new RequestLocalizationOptions
        {
            DefaultRequestCulture = new RequestCulture("en-GB"),
            SupportedCultures =
            {
                new CultureInfo("en-GB")
            },
            SupportedUICultures =
            {
                new CultureInfo("en-GB")
            }
        });
    }

3 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you log in admin and check the language management page?

  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    To do it with code;

    To remove all other languages and use English ("en-GB") by default, you can update the ConfigureServices method in the ProjectNameDomainModule file under the ProjectName.Domain folder to include the only "en-GB". For example, the content of the ConfigureServices method should now be as follows:

        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            ...
        	Configure<AbpLocalizationOptions>(options =>
            {
                options.Languages.Add(new LanguageInfo("en-GB", "en-GB", "English"));
            });
            ...
        }
    

    Then you should add the following to the OnApplicationInitialization method in the ProjectNameHttpApiHostModule file.

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

    Then just delete the data in the AbpLanguages table from the database and run ProjectName.DbMigrator.

  • User Avatar
    0
    ServiceBot created
    Support Team Automatic process manager

    This question has been automatically marked as stale because it has not had recent activity.

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