Use app.net Core to build a multi-language website, app. netcore

Source: Internet
Author: User

Use app.net Core to build a multi-language website, app. netcore
Asp.net Core has very few Chinese documents. You can read English documents, but English is also a bit messy. This article is dry. 1. configure your WebApplication so that it can support international languages and modify the document Startup. cs publicvoid ConfigureServices (IServiceCollection services) {services. addLocalization (options => options. resourcesPath = "Resources"); services. addMvc (). addViewLocalization (LanguageViewLocationExpanderFormat. suffix ). addDataAnnotationsLocalization ();} 2. modify your configuration public void Configure (IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory lo GgerFactory) {... the language that your website needs to support. Var supportedCultures = new [] {new CultureInfo ("en-US"), new CultureInfo ("zh-CN")}; here is the app that writes your default language. useRequestLocalization (new RequestLocalizationOptions {DefaultRequestCulture = new RequestCulture ("en-US"), // Formatting numbers, dates, etc. supportedCultures = supportedCultures, // UI strings that we have localized. supportedUICultures = supportedCultures});} 3. add resource document a to your view. add the Resources Directory B. press Your view path provides the structure of the resource document, for example, your view Views \ Home \ Index. cshtml your Resources \ Views \ Home \ Index. zh-CN.resx or Resources \ Views \ Home \ Index. en-US.resxc. add Key and Value d to the resource file. @ using Microsoft. aspNetCore. mvc. localization @ inject IViewLocalizer Localizer modify Learn More @ Localizer ["Learn More"] in the string to be displayed.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.