Hello Web API Series Tutorials: Web API and Internationalization

Source: Internet
Author: User
Tags date datetime resource thread tostring

Software internationalization is in software design and document development process, enables the function and the code design to be able to handle many languages and the cultural custom, when creates the different language version, does not need to redesign the source code the software engineering method. This is very common in many mature software development platforms. For. NET developers, we can generally implement the internationalization of the software in two different ways.

Language configuration file

Resource file

In the. NET platform, the internationalization of software depends primarily on the internationalization of the worker threads. In the processing thread of the. NET Framework, we set the Thread.CurrentCulture property to implement the format of the default values for date, time, number, currency value, text, load convention, and string comparisons, which are derived by default from the Control Panel The user culture in regional and language options. Of course, the Thread.CurrentCulture property value can also be forced to be changed manually during the software operation. The CurrentUICulture property is used to determine the resource format that needs to be presented to the user, which is most useful for the operational interface of the software, because it identifies the language that should be used when displaying UI elements. In. NET, the software is usually set up with different UI resource files, which enables the software runtime to select different language resource files to render the software interface through CurrentUICulture attribute values. The CurrentUICulture and CurrentCulture properties of a thread are generally set to the same CultureInfo object, which means that it uses the same language, country information, but it can also be set to a different object. For example, when an American borrows an operating system in Beijing to work in a simplified Chinese version of the computer, this way the software can be used to meet the needs of American users.

The following example explains that for different Thread.CurrentCulture property values, the same date string is converted to a date type to produce a different result

static void Main (string[] args)
        {
            string birthdate = "02/06/2013";
            datetime datetime;
            DateTime = DateTime.Parse (birthdate);
            Console.WriteLine (DateTime.ToString ("yyyy mm month DD day"));
            Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo ("EN-GB");
            DateTime = DateTime.Parse (birthdate);
            Console.WriteLine (DateTime.ToString ("yyyy mm month DD day"));
            Console.read ();
        }

The following example explains that for different Thread.CurrentUICulture property values, the framework selects different resource files to read the values in order to present different information to users who use different languages. Before running, you need to establish the following resource files in your project.

The contents of each resource file are as follows:

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.