久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<small id='nP5F0'></small><noframes id='nP5F0'>

<legend id='nP5F0'><style id='nP5F0'><dir id='nP5F0'><q id='nP5F0'></q></dir></style></legend>

    <bdo id='nP5F0'></bdo><ul id='nP5F0'></ul>
  1. <tfoot id='nP5F0'></tfoot>

      <i id='nP5F0'><tr id='nP5F0'><dt id='nP5F0'><q id='nP5F0'><span id='nP5F0'><b id='nP5F0'><form id='nP5F0'><ins id='nP5F0'></ins><ul id='nP5F0'></ul><sub id='nP5F0'></sub></form><legend id='nP5F0'></legend><bdo id='nP5F0'><pre id='nP5F0'><center id='nP5F0'></center></pre></bdo></b><th id='nP5F0'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='nP5F0'><tfoot id='nP5F0'></tfoot><dl id='nP5F0'><fieldset id='nP5F0'></fieldset></dl></div>

      Asp.net core Localization 總是返回英語文化

      Asp.net core Localization always returns english clulture(Asp.net core Localization 總是返回英語文化)
      <i id='ec4T5'><tr id='ec4T5'><dt id='ec4T5'><q id='ec4T5'><span id='ec4T5'><b id='ec4T5'><form id='ec4T5'><ins id='ec4T5'></ins><ul id='ec4T5'></ul><sub id='ec4T5'></sub></form><legend id='ec4T5'></legend><bdo id='ec4T5'><pre id='ec4T5'><center id='ec4T5'></center></pre></bdo></b><th id='ec4T5'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ec4T5'><tfoot id='ec4T5'></tfoot><dl id='ec4T5'><fieldset id='ec4T5'></fieldset></dl></div>

        <legend id='ec4T5'><style id='ec4T5'><dir id='ec4T5'><q id='ec4T5'></q></dir></style></legend>

          <small id='ec4T5'></small><noframes id='ec4T5'>

            <tfoot id='ec4T5'></tfoot>

                <tbody id='ec4T5'></tbody>
                <bdo id='ec4T5'></bdo><ul id='ec4T5'></ul>
                本文介紹了Asp.net core Localization 總是返回英語文化的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                我正在嘗試開發(fā)一個多語言項(xiàng)目.對于靜態(tài)值,我使用了資源(.resx 文件)

                I am trying to develop a multilanguage project.For static value I used resource(.resx file )

                我創(chuàng)建了兩個資源文件Home.resx(默認(rèn)或英語)和 home.resx(用于阿拉伯語)它適用于默認(rèn)或英語

                I create two resources file Home.resx(default or English) and home.resx(for the Arabic language) it works for default or English

                然后我嘗試更改語言

                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("ar");
                 var home = Resources.Home.Home1;
                

                但它仍然返回英文值而不是阿拉伯值

                But it still return English value instead of Arabic value

                這是我的 startup.cs 配置函數(shù)

                here is my startup.cs Configure function

                public void Configure(IApplicationBuilder app, IHostingEnvironment env)
                        {
                
                   var supportedCultures = new List<System.Globalization.CultureInfo>
                            {
                                new System.Globalization.CultureInfo("en-US"),
                
                                new System.Globalization.CultureInfo("ar-AR"),
                
                            };
                            var options = new RequestLocalizationOptions
                            {
                                DefaultRequestCulture = new Microsoft.AspNetCore.Localization.RequestCulture("en-US"),
                                SupportedCultures = supportedCultures,
                                SupportedUICultures = supportedCultures
                            };
                            app.UseRequestLocalization(options);
                ......
                

                我的代碼有什么問題?

                推薦答案

                好的,我會告訴你我在項(xiàng)目中做了什么.在 Startup.cs 的 ConfigureServices 方法中的 services.AddMvc() 之后鍵入以下代碼.

                Ok, I will tell you what I do in my projects. Type the following code after services.AddMvc() in your ConfigureServices method of the Startup.cs.

                IList<CultureInfo> supportedCultures = new List<CultureInfo>
                {
                    new CultureInfo("en-US"),
                    new CultureInfo("fr-FR"),
                    new CultureInfo("el-GR"),
                };
                
                var MyOptions = new RequestLocalizationOptions()
                {
                    DefaultRequestCulture = new RequestCulture(culture: "en-US", uiCulture: "en-US"),
                    SupportedCultures = supportedCultures,
                    SupportedUICultures = supportedCultures
                };
                MyOptions.RequestCultureProviders = new[]
                {
                     new RouteDataRequestCultureProvider() { RouteDataStringKey = "lang", Options = MyOptions }
                };
                
                services.AddSingleton(MyOptions);
                

                現(xiàn)在在您的項(xiàng)目中定義以下類

                Now define the following class in your project

                public class LocalizationPipeline
                {
                    public void Configure(IApplicationBuilder app, RequestLocalizationOptions options)
                    {
                        app.UseRequestLocalization(options);
                    }
                }
                

                更改您的默認(rèn)路由:

                app.UseMvc(routes =>
                {
                    routes.MapRoute(
                        name: "default",
                        template: "{lang=en-US}/{controller=Home}/{action=Index}/{id?}");
                });
                

                為每個控制器使用 MiddlewareFilter.

                In use the MiddlewareFilter for each of your controllers.

                [MiddlewareFilter(typeof(LocalizationPipeline))]
                public class HomeController : Controller
                {
                    public string GetCulture()
                    {
                        return $"CurrentCulture:{CultureInfo.CurrentCulture.Name}, CurrentUICulture:{CultureInfo.CurrentUICulture.Name}";
                    }
                }
                

                您可以像這樣更改當(dāng)前語言:

                You can change the current language like this:

                <ul>
                    <li>@Html.ActionLink("EN", ViewContext.RouteData.Values["action"] as string, ViewContext.RouteData.Values["controller"] as string, new { lang = "en-US" })</li>
                    <li>@Html.ActionLink("FR", ViewContext.RouteData.Values["action"] as string, ViewContext.RouteData.Values["controller"] as string, new { lang = "fr-FR" })</li>
                    <li>@Html.ActionLink("GR", ViewContext.RouteData.Values["action"] as string, ViewContext.RouteData.Values["controller"] as string, new { lang = "el-GR" })</li>
                </ul>
                

                如果您還想支持 Razor Pages,請進(jìn)行以下更改.添加以下更改 servcies.AddMvc().

                If you want to support Razor Pages as well, make the following changes. Add the following change the servcies.AddMvc().

                services.AddMvc()
                    .AddRazorPagesOptions(options =>
                    {
                        options.Conventions.AddFolderRouteModelConvention("/", model =>
                        {
                            foreach (var selector in model.Selectors)
                            {
                                var attributeRouteModel = selector.AttributeRouteModel;
                                attributeRouteModel.Template = AttributeRouteModel.CombineTemplates("{lang=el-GR}", attributeRouteModel.Template);
                            }
                        });
                    });
                

                在您的 PageModels 上使用以下 MiddlewareFilter 屬性

                Use the following MiddlewareFilter attribute over your PageModels

                [MiddlewareFilter(typeof(LocalizationPipeline))]
                public class ContactModel : PageModel
                {
                    public string Message { get; set; }
                
                    public void OnGet()
                    {
                        Message = "Your contact page.";
                    }
                }
                

                我唯一沒有做的事情是通過在 Startup.cs 中以編程方式添加 MiddlewareFilter 來為所有控制器和 PageModels 自動定義 LocalizationPipeline.

                The only thing that I have not managed to do is to automatically define the LocalizationPipeline for all the controllers and PageModels by adding the MiddlewareFilter programmatically inside the Startup.cs.

                這篇關(guān)于Asp.net core Localization 總是返回英語文化的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                相關(guān)文檔推薦

                GoogleWebAuthorizationBroker in MVC For Google Drive Access(MVC 中的 GoogleWebAuthorizationBroker 用于 Google Drive 訪問)
                Why do I get System.UnauthorizedAccessException Access to the path #39;Google.Apis.Auth#39; is denied(為什么我得到 System.UnauthorizedAccessException 對路徑“Google.Apis.Auth的訪問被拒絕) - IT屋-程序員軟件開發(fā)技術(shù)分享
                Dynamically built SiteMapPath in asp.net(在 asp.net 中動態(tài)構(gòu)建的 SiteMapPath)
                ASP.NET Exception: The remote name could not be resolved: #39;apiconnector.com#39;(ASP.NET 異常:無法解析遠(yuǎn)程名稱:“apiconnector.com)
                Does a MasterPage know what page is being displayed?(MasterPage 是否知道正在顯示的頁面?)
                ASP.net MVC - Navigation and highlighting the quot;currentquot; link(ASP.net MVC - 導(dǎo)航和突出顯示“當(dāng)前;關(guān)聯(lián))
                <legend id='Pu1KL'><style id='Pu1KL'><dir id='Pu1KL'><q id='Pu1KL'></q></dir></style></legend>

                    <tbody id='Pu1KL'></tbody>
                1. <small id='Pu1KL'></small><noframes id='Pu1KL'>

                      • <tfoot id='Pu1KL'></tfoot>

                        <i id='Pu1KL'><tr id='Pu1KL'><dt id='Pu1KL'><q id='Pu1KL'><span id='Pu1KL'><b id='Pu1KL'><form id='Pu1KL'><ins id='Pu1KL'></ins><ul id='Pu1KL'></ul><sub id='Pu1KL'></sub></form><legend id='Pu1KL'></legend><bdo id='Pu1KL'><pre id='Pu1KL'><center id='Pu1KL'></center></pre></bdo></b><th id='Pu1KL'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Pu1KL'><tfoot id='Pu1KL'></tfoot><dl id='Pu1KL'><fieldset id='Pu1KL'></fieldset></dl></div>
                          <bdo id='Pu1KL'></bdo><ul id='Pu1KL'></ul>
                        • 主站蜘蛛池模板: 欧美中文字幕 | 在线观看中文视频 | 中文字幕在线精品 | 精品一区二区三区四区在线 | 天天搞夜夜操 | 国产在线播 | 久热m3u8| av一区在线观看 | 日韩视频中文字幕 | 激情六月丁香婷婷 | 老子午夜影院 | 欧美精品91爱爱 | 亚洲精品乱码久久久久久蜜桃91 | 成人一区二区三区在线观看 | 日韩1区2区 | 久久综合伊人一区二区三 | 精品国产欧美 | 777zyz色资源站在线观看 | av国产精品| 一级片在线观看 | 日本久草 | 欧美一区二区三区久久精品 | 美女天天操 | 亚洲成人一区二区 | 国产日韩欧美激情 | 久久综合一区 | 国产精品久久久久久久7777 | 男人天堂免费在线 | 亚欧精品一区 | 国产在线视频一区二区 | 亚洲精品电影在线观看 | 九九久久久久久 | 中文字幕国产精品 | 欧美福利专区 | 国产午夜精品久久 | 午夜av影院 | 婷婷成人在线 | 久久99蜜桃综合影院免费观看 | 久久综合欧美 | 一区二区三区视频在线 | 国产亚洲一区二区三区 |