Home > database >  Rename "culture" query parameter in ASP.NET for localization
Rename "culture" query parameter in ASP.NET for localization

Time:12-15

Just managed to setup the basic localization settings in Startup.cs:

public void ConfigureServices(IServiceCollection services)
{
    services.AddLocalization(options => options.ResourcesPath = "Resources");
    // ...
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IFinancialsCWSUnitOfWork financialsCwsUnitOfWork)
{
    var supportedCultures = new[]
    {
        new CultureInfo("en-US"),
        new CultureInfo("fr-FR")
    };

    var requestLocalizationOptions = new RequestLocalizationOptions
    {
        DefaultRequestCulture = new RequestCulture("en-US"),
        SupportedCultures = supportedCultures,
        SupportedUICultures = supportedCultures
    };

    app.UseRequestLocalization(requestLocalizationOptions);

    // . . .
}

Which works just fine. But the issue here is that I need to use a "culture" query parameter. Is there a way to rename "culture" to "language"? I need it in that specific way - a query parameter, named "language".

CodePudding user response:

try

var requestLocalizationOptions = new RequestLocalizationOptions
{
    DefaultRequestCulture = new RequestCulture("en-US"),
    SupportedCultures = supportedCultures,
    SupportedUICultures = supportedCultures,
    RequestCultureProviders = new List()
    {
        new QueryStringRequestCultureProvider()
        {
            QueryStringKey = "language"
        }
    }
};
  • Related