pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<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="mqsumic" 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="a20miym" 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 總是返回英語文化的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

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

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

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

                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 配置函數

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

                我的代碼有什么問題?

                推薦答案

                好的,我會告訴你我在項目中做了什么.在 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);
                

                現在在您的項目中定義以下類

                Now define the following class in your project

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

                更改您的默認路由:

                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}";
                    }
                }
                

                您可以像這樣更改當前語言:

                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,請進行以下更改.添加以下更改 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.

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

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

                相關文檔推薦

                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屋-程序員軟件開發技術分享
                Dynamically built SiteMapPath in asp.net(在 asp.net 中動態構建的 SiteMapPath)
                ASP.NET Exception: The remote name could not be resolved: #39;apiconnector.com#39;(ASP.NET 異常:無法解析遠程名稱:“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 - 導航和突出顯示“當前;關聯)
                <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="2esugqg" id='Pu1KL'><tfoot id='Pu1KL'></tfoot><dl id='Pu1KL'><fieldset id='Pu1KL'></fieldset></dl></div>
                          <bdo id='Pu1KL'></bdo><ul id='Pu1KL'></ul>
                        • 主站蜘蛛池模板: 品牌广告服务平台,好排名,好流量,好生意。 | 陕西视频监控,智能安防监控,安防系统-西安鑫安5A安防工程公司 | 鹤壁创新仪器公司-全自动量热仪,定硫仪,煤炭测硫仪,灰熔点测定仪,快速自动测氢仪,工业分析仪,煤质化验仪器 | 自动检重秤-动态称重机-重量分选秤-苏州金钻称重设备系统开发有限公司 | 伶俐嫂培训学校_月嫂培训班在哪里报名学费是多少_月嫂免费政府培训中心推荐 | 高防护蠕动泵-多通道灌装系统-高防护蠕动泵-www.bjhuiyufluid.com慧宇伟业(北京)流体设备有限公司 | 电气控制系统集成商-PLC控制柜变频控制柜-非标自动化定制-电气控制柜成套-NIDEC CT变频器-威肯自动化控制 | 哈尔滨发电机,黑龙江柴油发电机组-北方星光 | 亿诺千企网-企业核心产品贸易| 耐酸碱胶管_耐腐蚀软管总成_化学品输送软管_漯河利通液压科技耐油耐磨喷砂软管|耐腐蚀化学软管 | 神超官网_焊接圆锯片_高速钢锯片_硬质合金锯片_浙江神超锯业制造有限公司 | 回转支承-转盘轴承-回转驱动生产厂家-洛阳隆达轴承有限公司 | 电磁流量计厂家_涡街流量计厂家_热式气体流量计-青天伟业仪器仪表有限公司 | 加热制冷恒温循环器-加热制冷循环油浴-杭州庚雨仪器有限公司 | 长沙一级消防工程公司_智能化弱电_机电安装_亮化工程专业施工承包_湖南公共安全工程有限公司 | 聚氨酯保温钢管_聚氨酯直埋保温管道_聚氨酯发泡保温管厂家-沧州万荣防腐保温管道有限公司 | 智能终端_RTU_dcm_北斗星空自动化科技| 吨袋包装机|吨包秤|吨包机|集装袋包装机-烟台华恩科技 | 干粉砂浆设备_干混砂浆生产线_腻子粉加工设备_石膏抹灰砂浆生产成套设备厂家_干粉混合设备_砂子烘干机--郑州铭将机械设备有限公司 | 华禹护栏|锌钢护栏_阳台护栏_护栏厂家-华禹专注阳台护栏、楼梯栏杆、百叶窗、空调架、基坑护栏、道路护栏等锌钢护栏产品的生产销售。 | 立式壁挂广告机厂家-红外电容触摸一体机价格-华邦瀛 | 京马网,京马建站,网站定制,营销型网站建设,东莞建站,东莞网站建设-首页-京马网 | 走心机厂家,数控走心机-台州博城智能科技有限公司 | 爱佩恒温恒湿测试箱|高低温实验箱|高低温冲击试验箱|冷热冲击试验箱-您身边的模拟环境试验设备技术专家-合作热线:400-6727-800-广东爱佩试验设备有限公司 | 首页-浙江橙树网络技术有限公司| 蔬菜配送公司|蔬菜配送中心|食材配送|饭堂配送|食堂配送-首宏公司 | 蓄电池回收,ups电池后备电源回收,铅酸蓄电池回收,机房电源回收-广州益夫铅酸电池回收公司 | 刮板输送机,粉尘加湿搅拌机,螺旋输送机,布袋除尘器 | 高低温万能试验机-复合材料万能试验机-馥勒仪器 | 英思科GTD-3000EX(美国英思科气体检测仪MX4MX6)百科-北京嘉华众信科技有限公司 | 商用绞肉机-熟肉切片机-冻肉切丁机-猪肉开条机 - 广州市正盈机械设备有限公司 | 太阳能发电系统-太阳能逆变器,控制器-河北沐天太阳能科技首页 | 卫浴散热器,卫浴暖气片,卫生间背篓暖气片,华圣格浴室暖气片 | 安徽净化工程设计_无尘净化车间工程_合肥净化实验室_安徽创世环境科技有限公司 | 耐腐蚀泵,耐腐蚀真空泵,玻璃钢真空泵-淄博华舜耐腐蚀真空泵有限公司 | 写方案网_方案策划方案模板下载| 政府园区专业委托招商平台_助力企业选址项目快速落地_东方龙商务集团 | 防火门-专业生产甲级不锈钢钢质防火门厂家资质齐全-广东恒磊安防设备有限公司 | 河南膏药贴牌-膏药代加工-膏药oem厂家-洛阳今世康医药科技有限公司 | 食品机械专用传感器-落料放大器-低价接近开关-菲德自控技术(天津)有限公司 | 植筋胶-粘钢胶-碳纤维布-碳纤维板-环氧砂浆-加固材料生产厂家-上海巧力建筑科技有限公司 |