Home Backend Development C#.Net Tutorial Detailed introduction to multi-language support in ASP.NET Core

Detailed introduction to multi-language support in ASP.NET Core

Sep 01, 2017 pm 02:23 PM
asp.net core language

This article mainly introduces the multi-language support (Localization) in ASP.NET Core, which has certain reference value. Those who are interested can learn about it

First add AddLocalization and AddViewLocalization in ConfigureServices of Startup And configure RequestLocalizationOptions (assuming English and Chinese are used here):


public void ConfigureServices(IServiceCollection services)
{
  services.AddLocalization(options => options.ResourcesPath = "Resources");

  services.AddMvc()
    .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix);

  services.Configure<RequestLocalizationOptions>(
    opts =>
    {
      var supportedCultures = new List<CultureInfo>
      {
        new CultureInfo("en-US"),
        new CultureInfo("zh-CN")
      };
      opts.SupportedCultures = supportedCultures;
      opts.SupportedUICultures = supportedCultures;
    });
}
Copy after login

Apply RequestLocalizationOptions in the Configure() method of Startup:


var requestLocalizationOptions = app.ApplicationServices.GetService<IOptions<RequestLocalizationOptions>>().Value;
app.UseRequestLocalization(requestLocalizationOptions);
Copy after login

Then display the suffix of the page title in a multi-lingual manner through the IViewLocalizer interface in the _Layout.cshtml view:


@using Microsoft.AspNetCore.Mvc.Localization
@inject IViewLocalizer Localizer
<!DOCTYPE html>
<html>
<head>
  <title>@ViewData["Title"] - @Localizer["SiteTitle"]</title>
</head>
<body>
</body>
</html>
Copy after login

Then in ASP.NET Core Web Create the Resources folder in the project, add the Views.Shared._Layout.en-Us.resx and Views.Shared._Layout.zh-CN.resx files, the Views.Shared._Layout.resx file respectively, and add "SiteTitle" The corresponding statement text:

1) Views.Shared._Layout.en-Us.resx

##2) Views.Shared._Layout.zh- CN.resx

#When running the ASP.NET Core site, it will be based on the browser's language setting (Accept-Language header), or culture query parameters, or .AspNetCore .Culture Cookie value displays the text of the corresponding language:

# Things to note: Never add Views without a language name. Shared._Layout.en-Us.resx, otherwise 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. Question

The above is the detailed content of Detailed introduction to multi-language support in ASP.NET Core. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to Completely Remove Unwanted Display Languages ​​on Windows 11 How to Completely Remove Unwanted Display Languages ​​on Windows 11 Sep 24, 2023 pm 04:25 PM

Work on the same setup for too long or share your PC with others. You may have some language packs installed, which often create conflicts. So, it’s time to remove unwanted display languages ​​in Windows 11. Speaking of conflicts, when there are multiple language packs, inadvertently pressing Ctrl+Shift changes the keyboard layout. If not taken care of, this can be a hindrance to the task at hand. So, let’s jump right into the method! How to remove display language from Windows 11? 1. From Settings press + to open the Settings app, go to Time & Language from the navigation pane and click on Language & Region. WindowsI click the ellipsis next to the display language you want to remove and select Remove from the pop-up menu. Click "

How to enable Core Isolation's memory integrity feature in Windows 11 How to enable Core Isolation's memory integrity feature in Windows 11 May 10, 2023 pm 11:49 PM

Microsoft's Windows 11 2022 Update (22H2) enables CoreIsolation's memory integrity protection by default. However, if you are running an older version of the operating system, such as Windows 11 2022 Update (22H1), you will need to turn this feature on manually. Turn on CoreIsolation's Memory Integrity feature in Windows 11 For users who don't know about Core Isolation, it's a security process designed to protect basic core activities on Windows from malicious programs by isolating them in memory. This process, combined with the memory integrity feature, ensures

3 Ways to Change Language on iPhone 3 Ways to Change Language on iPhone Feb 02, 2024 pm 04:12 PM

It's no secret that the iPhone is one of the most user-friendly electronic gadgets, and one of the reasons why is that it can be easily personalized to your liking. In Personalization, you can change the language to a different language than the one you selected when setting up your iPhone. If you're familiar with multiple languages, or your iPhone's language setting is wrong, you can change it as we explain below. How to Change the Language of iPhone [3 Methods] iOS allows users to freely switch the preferred language on iPhone to adapt to different needs. You can change the language of interaction with Siri to facilitate communication with the voice assistant. At the same time, when using the local keyboard, you can easily switch between multiple languages ​​to improve input efficiency.

Adding comprehensive audio-visual capabilities to large language models, DAMO Academy opens source Video-LLaMA Adding comprehensive audio-visual capabilities to large language models, DAMO Academy opens source Video-LLaMA Jun 09, 2023 pm 09:28 PM

Video plays an increasingly important role in today's social media and Internet culture. Douyin, Kuaishou, Bilibili, etc. have become popular platforms for hundreds of millions of users. Users share their life moments, creative works, interesting moments and other content around videos to interact and communicate with others. Recently, large language models have demonstrated impressive capabilities. Can we equip large models with "eyes" and "ears" so that they can understand videos and interact with users? Starting from this problem, researchers from DAMO Academy proposed Video-LLaMA, a large model with comprehensive audio-visual capabilities. Video-LLaMA can perceive and understand the video and audio signals in the video, and can understand the instructions input by the user to complete a series of complex tasks based on audio and video,

How to set the language of Win10 computer to Chinese? How to set the language of Win10 computer to Chinese? Jan 05, 2024 pm 06:51 PM

Sometimes we just install the computer system and find that the system is in English. In this case, we need to change the computer language to Chinese. So how to change the computer language to Chinese in the win10 system? Now Give you specific operation methods. How to change the computer language in win10 to Chinese 1. Turn on the computer and click the start button in the lower left corner. 2. Click the settings option on the left. 3. Select "Time and Language" on the page that opens. 4. After opening, click "Language" on the left. 5. Here you can set the computer language you want.

How to Fix Processor Thermal Trip Error in Windows 11/10 [Fix] How to Fix Processor Thermal Trip Error in Windows 11/10 [Fix] Apr 17, 2023 am 08:13 AM

Most of the devices, such as laptops and desktops, have been heavily used by young gamers and coders for a long time. The system sometimes hangs due to application overload. This forces users to shut down their systems. This mainly happens to players who install and play heavy games. When the system tries to boot after force shutdown, it throws an error on a black screen as shown below: Below are the warnings detected during this boot. These can be viewed in the settings on the event log page. Warning: Processor thermal trip. Press any key to continue. ..These types of warning messages are always thrown when the processor temperature of a desktop or laptop exceeds its threshold temperature. Listed below are the reasons why this happens on Windows systems. Many heavy applications are in

Exploring the boundaries of agents: AgentQuest, a modular benchmark framework for comprehensively measuring and improving the performance of large language model agents Exploring the boundaries of agents: AgentQuest, a modular benchmark framework for comprehensively measuring and improving the performance of large language model agents Apr 11, 2024 pm 08:52 PM

Based on the continuous optimization of large models, LLM agents - these powerful algorithmic entities have shown the potential to solve complex multi-step reasoning tasks. From natural language processing to deep learning, LLM agents are gradually becoming the focus of research and industry. They can not only understand and generate human language, but also formulate strategies, perform tasks in diverse environments, and even use API calls and coding to Build solutions. In this context, the introduction of the AgentQuest framework is a milestone. It not only provides a modular benchmarking platform for the evaluation and advancement of LLM agents, but also provides researchers with a Powerful tools to track and improve the performance of these agents at a more granular level

You can play Genshin Impact just by moving your mouth! Use AI to switch characters and attack enemies. Netizen: 'Ayaka, use Kamiri-ryu Frost Destruction' You can play Genshin Impact just by moving your mouth! Use AI to switch characters and attack enemies. Netizen: 'Ayaka, use Kamiri-ryu Frost Destruction' May 13, 2023 pm 07:52 PM

When it comes to domestic games that have become popular all over the world in the past two years, Genshin Impact definitely takes the cake. According to this year’s Q1 quarter mobile game revenue survey report released in May, “Genshin Impact” firmly won the first place among card-drawing mobile games with an absolute advantage of 567 million U.S. dollars. This also announced that “Genshin Impact” has been online in just 18 years. A few months later, total revenue from the mobile platform alone exceeded US$3 billion (approximately RM13 billion). Now, the last 2.8 island version before the opening of Xumi is long overdue. After a long draft period, there are finally new plots and areas to play. But I don’t know how many “Liver Emperors” there are. Now that the island has been fully explored, grass has begun to grow again. There are a total of 182 treasure chests + 1 Mora box (not included). There is no need to worry about the long grass period. The Genshin Impact area is never short of work. No, during the long grass

See all articles