提问者:小点点

在ASP中重命名“文化”查询参数。NET进行本地化


只是在启动时设置了基本的本地化设置。反恐精英:

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

    // . . .
}

这很好用。但这里的问题是我需要使用一个“culture”查询参数。有没有办法把“文化”改名为“语言”?我需要它以这种特定的方式-一个名为“language”的查询参数。


共1个答案

匿名用户

试试看

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