In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
The editor will share with you the example analysis of multilingual support in ASP.NET Core. I hope you will get something after reading this article. Let's discuss it together.
First, add AddLocalization and AddViewLocalization to the ConfigureServices of Startup and configure RequestLocalizationOptions (English and Chinese are assumed here):
Public void ConfigureServices (IServiceCollection services) {services.AddLocalization (options = > options.ResourcesPath = "Resources"); services.AddMvc () .AddViewLocalization (LanguageViewLocationExpanderFormat.Suffix); services.Configure (opts = > {var supportedCultures = new List {new CultureInfo ("en-US"), new CultureInfo ("zh-CN")}; opts.SupportedCultures = supportedCultures; opts.SupportedUICultures = supportedCultures;});}
Apply RequestLocalizationOptions in the Configure () method of Startup:
Var requestLocalizationOptions = app.ApplicationServices.GetService () .Value;app.UseRequestLocalization (requestLocalizationOptions)
Then display the suffix of the page title in multiple languages through the IViewLocalizer interface in the _ Layout.cshtml view:
@ using Microsoft.AspNetCore.Mvc.Localization@inject IViewLocalizer Localizer @ ViewData ["Title"]-@ Localizer ["SiteTitle"]
Then create a Resources folder in the ASP.NET Core Web project, add Views.Shared._Layout.en-Us.resx and Views.Shared._Layout.zh-CN.resx files, Views.Shared._Layout.resx files, and add the statement text corresponding to "SiteTitle":
1) Views.Shared._Layout.en-Us.resx
2) Views.Shared._Layout.zh-CN.resx
When you run the ASP.NET Core site, the text of the corresponding language is displayed based on the browser's language setting (Accept-Language header), or the culture query parameter, or the .AspNetCore. Culture Cookie value:
Note: never add a Views.Shared._Layout.en-Us.resx without a language name, or you will encounter "Custom tool ResXFileCodeGenerator failed to produce an output for input file. But did not log a specific error." when adding a .resx file with a code language name. Ask
After reading this article, I believe you have some understanding of "sample Analysis of multilingual support in ASP.NET Core". If you want to know more about it, please follow the industry information channel. Thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.