ASP.NET Core Request Localization Options

后端 未结 4 1322
失恋的感觉
失恋的感觉 2021-02-05 08:17

Here is my custom request culture provider which returns \"en\" as a default culture if no culture specified in url (for example http://sypalo.com/ru or http://sypalo.com/en). M

4条回答
  •  误落风尘
    2021-02-05 08:45

    as an additional option, Here is a full solution: Handle culture in route (URL) via RequestCultureProviders

    as an option as well, here is a simplified code for CustomRequestCultureProvider:

    options.RequestCultureProviders.Insert(0, new CustomRequestCultureProvider(context =>
    {
        var lang = context.Request.GetTypedHeaders().AcceptLanguage.FirstOrDefault()?.Value.Value ?? Constants.Languages.EN_US;
    
        return Task.FromResult(new ProviderCultureResult(lang, lang));
    
    }));
    

提交回复
热议问题