The opening

I wrote a multi language application in my early years :    localization ( Multilingual )    Describes how to create a multilingual resource file , And use the resource file to get the language properties of the page and request

This supplement to this article , The reason for this is that in actual projects , There are many situations that require multilingualism

such as : The log should be displayed according to the current language

And some scenarios are more complex , We could key It's extracted from the data , Or some error prompts and display of model interface fields

Now let's review and add some practical applications

1. Multilingual use

Basic use of multi language , Please jump to the connection I wrote in the early years of the beginning   localization ( Multilingual )

The multilingual namespace is using System.Threading;

So on the back end .cs Page or front view , You have to quote  System.Threading

2. Get the name of the current multilingual

string info = System.Threading.Thread.CurrentThread.CurrentCulture.Name;

Get the language name of the resource file en-US  /  zh-CN  / zh-TW

3. Change the language of the current request

For example, when the user requests, the language is zh-CN, That is Chinese , Through the following 3 Line code can be set to change the current request language

CultureInfo culture = CultureInfo.GetCultureInfo("en-US");
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;

Sample code

public ActionResult Create(string name)
{
int a=1; CultureInfo culture = CultureInfo.GetCultureInfo("en-US");
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture; return View(Resource. Create success );
}

When not in use , return : Create success   When used, returns :Insert Succeed

3. Usage mode

Because the back-end code of the resource file is also a class ,Key Attribute , It's very easy to use

string value1 = Resource.Key00001;
string value2 = Resource.Key00002;

4. Use scenario 1

Take a chestnut :

For example, I want to write a diary : among full name And the phone is a variable

   Zhang San successfully created a customer information , Customer name : Li Si , Customer phone :13800138000

Then you can use formatting to fill in the display , In the log , Just store the value

string.Format(Resource.Key0001, " Li Si ", "138XXXXXXXX");

5. adopt Key The reflected value

If you don't like the scene above , Then you can use the following method , take key With the value to the database

for instance : Table data -   Key00002: Zhang San

Then it can be extracted by asset management manager Key To reflect

ResourceManager resMan = new ResourceManager(typeof(Resource));
string val = resMan.GetString("Key000002");

6.MVC Comments on model properties in

Annotations are mainly used for 2 A place to

  • 1. Errors in model validation
  • 2.DisplayFor Interface display

Let's take an example :

4 individual key Middle front 2 One is an error message

So that's what our model does

[Display(Name = "Key00003", ResourceType = typeof(Resource))]
[Required(ErrorMessageResourceType = typeof(Resource), ErrorMessageResourceName = "Key00001")]
public string Name { get; set; }

Then you will get a non empty through translation prompt and a front-end display translation processing , This MVC It's the simplest and the most perfect

@Html.LabelFor(model => model.Name)
Get the field
@Html.ValidationMessageFor(model => model.Name)
Error message

Last

If your system is used in many countries , Or a system with many people in different areas using

So the knowledge of this article is very practical , Because by dealing with

It can make some fixed general parts of the data originally in the database also get perfect translation

ASP.NET MVC5+EF6+EasyUI Background management system (89)- internationalization , localization , More articles on multilingual applications

  1. ASP.NET MVC5+EF6+EasyUI Background management system (1)- Preface and table of contents ( Ongoing update ...)

    development tool :VS2015(2012 above )+SQL2008R2 Above database   You can get the latest source code for a fee QQ:729994997  Price 666RMB   After upgrading, the interface effect is as follows : Task scheduling system interface  http: ...

  2. ASP.NET MVC5+EF6+EasyUI Background management system (63)-Excel Import and export - Custom table schema import

    Series catalog Preface The last section used LinqToExcel and CloseXML Yes Excel Table for import and export simple operation , You can jump to the previous section to see : ASP.NET MVC5+EF6+EasyUI Background management system (6 ...

  3. ASP.NET MVC5+EF6+EasyUI Background management system -WebApi The usage and debugging of

    1:ASP.NET MVC5+EF6+EasyUI Background management system (1)-WebApi And Unity Inject   Use Unity To use our backstage BLL and DAL layer 2:ASP.NET MVC5+EF6+Easy ...

  4. ASP.NET MVC5+EF6+EasyUI Background management system (1)- Preface and table of contents ( turn )

    development tool :VS2015(2012 above )+SQL2008R2 Above database You can get the latest source code for a fee QQ:729994997 Price 666RMB After upgrading, the interface effect is as follows : Schedule management    http://ww ...

  5. ASP.NET MVC5+EF6+EasyUI Background management system (51)- System upgrade

    The system hasn't updated the content for a long time , The long-awaited update was released today , Recently spent 2 A little bit every day for three months , From the original system MVC4+EF5+UNITY2.X+Quartz 2.0+easyui 1.3.4 Seamless access MVC5+E ...

  6. ASP.NET MVC5+EF6+EasyUI Background management system (58)-DAL Layer refactoring

    Series catalog Preface : This is an important innovation of this system , It's been a long time since I wanted to refactor the data access layer , There are too many duplicate codes in the data access layer . It's mainly about adding and deleting. Each module has , So this time it's for encapsulating the same interface method If you want to know how to refactor normal interfaces DAL Please check ...

  7. ASP.NET MVC5+EF6+EasyUI Background management system (34)- Article publishing system ①- Brief analysis

    Series catalog The latest is relatively free , In order to learn Android The development and construction of ASP.NET MVC4+EF5+EasyUI+Unity2.x Background management system of injection (1)- Preface and , Although a little purposeless learning , But I understand Andro ...

  8. ASP.NET MVC5+EF6+EasyUI Background management system (54)- Workflow design - All process monitoring

    Series catalog First add a flat landing page code , Change your favorite color background @using Apps.Common; @{ Layout = null; } <!DOCTYPE html> <ht ...

  9. ASP.NET MVC5+EF6+EasyUI Background management system (56)- plug-in unit --- Single file upload and easyui Use fancybox

    Series catalog https://yunpan.cn/cZVeSJ33XSHKZ   Access password 0fc2 Today's integration lightbox plug-in unit Fancybox1.3.4, Find out 1.3.4 The version is too old . Now, easyui 1 ...

  10. ASP.NET MVC5+EF6+EasyUI Background management system (38)-Easyui-accordion+tree Beautiful menu navigation

    Series catalog The main knowledge points of this section are easyui Accordion plus tree structure for menu navigation Some garden friends complained that the original menu was very ugly , But based on the original tree infinite level design , There's no way but to show it in the form of a tree Let's look at the original effect first The effect of the change , Of course I've done it ...

Random recommendation

  1. LoadRunner Replace string ( You can replace multiple )

    stay global.h Add code to /* * @param char* dest  The target string , That is, the new string after replacement * @param const char* src  The source string , Replaced string * @param c ...

  2. MVVM Design patterns 《 Netting 》

    MVVM Patterns can help you separate the business and presentation logic of your application from the user interface . Keeping program logic separate from interface can help solve many development and design problems , Can make your program easier to test , Maintenance and upgrade . It can also greatly increase code reusability , and ...

  3. Some useful Emacs To configure ( Windows switch quickly 、 One click transparency 、 Delete the whole line anywhere )

    This article records some useful Emacs To configure , Some of them are original , Some learn from others ( Can remember the source of I put the link ). Regulations :C representative Ctrl,M representative Alt. 1. Set up a jump n Shortcut keys for lines Press C-M- ...

  4. 【 One day LeetCode】#260. Single Number III

    One day LeetCode All articles in this series have been uploaded to my github, Address :ZeeCoder's Github Welcome to my Sina Weibo , My Sina Weibo Welcome to reprint , Reprint please indicate the source ( One ) subject Given a ...

  5. Apache Hadoop 2.9.2 Analysis of the filing cases of

    Apache Hadoop 2.9.2 Analysis of the filing cases of author : Yin Zhengjie Copyright notice : Original works , Declined reprint ! Otherwise, the legal liability will be investigated .   Seeing this article shows that you are right about NameNode I have a deep understanding of the working principle ! We know ...

  6. Learning notes 70—Photoshop Drawing gears

    The specific steps are as follows : 1) Select the polygon tool : 2) Set the number of gears and corresponding parameters of color : 3) Draw a model : 4) Find the center of the model above ( With the help of :ctrl + T), Select the Ellipse Tool , and Long press Shift+Alt, Draw a circle : 5) ...

  7. Reprint : How to be in Ubuntu 18.04 Upper use UFW Set up firewall

    https://blog.csdn.net/u013068789/article/details/82051943 Introduce UFW or Uncomplicated Firewall yes iptables An interface ...

  8. [java,2018-02-24] svn The checked out project name is incorrect

    , Today from svn Found when checking out items in , The name of the checked out item is not the same as the actual , Here's the picture : That's why I remember , At that time, the project was created at random test As the project name , Later I thought it would work , It's just me Change the name of the project directly , Submitted to svn. Again from ...

  9. Python Learn the first chapter

    1.Python Reserved words are keywords , We can't think of them as any identifier name . python The standard library of provides a keyword Templates , Can output the current version of the keyword : >>>import keywor ...

  10. vue.js Environment configuration steps and npm run dev Error reporting solutions

    After installation , Use npm run dev function , After success , You can see it in the browser vue Welcome screen of The last step may be an error , That's what happened to me , Personal questions are for reference only : ERROR Failed to compil ...