Use App.net core to make multi-lingual websites.

Source: Internet
Author: User

The ASP. NET Core Chinese documents are very few, you can look at English, but the English is also a bit messy. This article is dry. 1. Configure your webapplication so that he can support the internationalization language, 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 loggerfactory){...This contains the languages that your website needs to support.             var supportedcultures = New[]            {                New CultureInfo("en -us"),                New CultureInfo("ZH-CN")            };This is the default language you write .app. Userequestlocalization (New requestlocalizationoptions            {defaultrequestculture = New requestculture("en -us"),                //formatting numbers, dates, etc.supportedcultures = supportedcultures,                //UI strings that we have localized.supporteduicultures = SupportedCultures            });3. Add resources to your view document A. Add Resources directory B. According to your view path, give the structure of the resource document such as your view views\home\index.cshtml your resources resources\views\home\ Index.zh-cn.resx or RESOURCES\VIEWS\HOME\INDEX.EN-US.RESXC. Add key and Value D to the resource file. Top of view@using Microsoft.AspNetCore.Mvc.Localization@inject Iviewlocalizer Localizerthe string that needs to be displayedwill beLearn moreModify@Localizer ["Learn More"]Test RunGet some.

Use App.net core to make multi-lingual websites.

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.