简体   繁体   English

如何在 .net 5 web API 中添加语言本地化

[英]How to add Language localization in .net 5 web API

I have tried to follow the steps of this tutorial to Apply Language localization at my API level.我已尝试按照本教程的步骤在我的 API 级别应用语言本地化。 but what ever the HTTP request Header is, it alwase brings the default Language.但是无论 HTTP 请求标头是什么,它总是带来默认语言。 this is the startup Code, in ConfigureServices method:这是启动代码,在ConfigureServices方法中:

  #region Localiztion
        services.AddLocalization();
        services.AddRequestLocalization(x =>
        {
            x.DefaultRequestCulture = new RequestCulture("en");

            x.ApplyCurrentCultureToResponseHeaders = true;

            x.SupportedCultures = new List<CultureInfo> {
                new("ar"),
                new("en") 
            };

             x.SupportedUICultures = new List<CultureInfo> {
                new("ar"),
                new("en")
            };

        });
        #endregion

at Configure method :Configure方法:

  app.UseRequestLocalization();

the resources :资源:

在此处输入图片说明

I have tried to add culture header as mentioned in the tutorial or adding Content-Language header as mentioned on Microsoft Docs but still, it only brings the default whatever the default is.我尝试添加教程中提到的culture标头或添加Microsoft Docs上提到的Content-Language标头,但它仍然只带来默认值。

经过一番研究,与本地化一起使用的 HTTP 标头是Accept-Language

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM