Implementation of multi-language support in the. NET Framework

Source: Internet
Author: User
Tags resource visual studio
Objective
Ever remember in Win32 's native code programming era, to achieve a multilingual interface and racked my brains, so a lot of tutorials are taught you how to enable the program to achieve multi-language support, these methods of implementation of the technical level is uneven, it is difficult to find a good framework to implement in the business process. The arrival of the NET era, We suddenly find it all so simple that you can make your program perfect for multi-language support with an easy click of your mouse.
I do not want to explain the concepts that appear in this article too much here, because MSDN has provided us with fully localized technical documentation.

Body
I used the visual c#.net in Visual Studio 2003 to implement the Demo, which I designed not only to automate the localization of the current locale, but also to manually change the interface language and implement a custom resource localization. Demo source download here.
Please follow my steps to complete:
Create a new Windows application named "MultiLanguage".
In the Properties window, set the form's Localizable property to true.
The Language property has been set to (default).
Drag the MainMenu, PictureBox, button controls from the Windows Forms tab of the Toolbox onto the form, and then follow the layout and design of the controls in the Demo form that I set up.
Set the Language property of the form to Chinese (People's Republic of China).
Re-follow the layout and design of the Chinese interface for these controls in my Demo form.
Click the Show All Files button in Solution Explorer.
The resource file appears below the Form1.cs. Form1.resx is a resource file for the fallback culture, which is generated into the main assembly. Form1.zh-cn.resx is a resource file for Simplified Chinese spoken in China.
Generate the Click event for the menu item separately, and add it to the event handling section according to the implementation code I have in the Demo.
We mainly learn how I dynamically modify all language-related elements of the interface, including strings, objects (such as Picturebox.image).
On the Project menu, click Add New Item.
In the Template box, select the assembly resource file template. Type the filename "Winformstrings.resx" in the Name box. The Winformstrings.resx file will contain the backup resources for English. These resources are accessed whenever the application cannot find a resource that is more appropriate for the UI culture.
The file is added to the project in Solution Explorer and is automatically opened in the XML designer in the form of Data View.
In the datasheet pane, select Data.
In the Data pane, click a blank row and enter "Strmessage" in the Name column, and enter "Hello World" in the "Value" column.
On the File menu, click Save Winformstrings.resx.
Repeat step 8-12 two to create a resource file named "Winformstrings.zh-cn.resx," and this file has the string resource specified in the following table. The Winformstrings.zh-cn.resx file will contain resources specific to Simplified Chinese spoken in China.
Resource file name Name value
Winformstrings.zh-cn.resx strmessage Hello! World

Generate the Button1 Click event and add it to the event handling section according to the implementation code I have in the Demo.
This section focuses on how to access manually added resources to generate localizable strings that appear in dialog boxes and error messages as you program later.
Add the code for the constructor Form1 (), as I did in the Demo.
Save and build the solution.
Compile and try to run.
I was compiled with release mode, in the project directory under the Multilanguage\bin\release will generate two subdirectories "Zh-chs", "ZH-CN", there is a called "MultiLanguage.resources.dll file that corresponds to the resource file for the fallback culture you designed in the form. Publish with the final compiler, do not change any directory settings in the Bin directory, the. NET Framework will be localized according to a certain rule, refer to the MSDN appropriate section.

Reference
MSDN Feb 2003 Simplified Chinese version. specifically see
Ms-help://ms. Msdnqtr.2003feb.2052/vbcon/html/vbwlkwalkthroughlocalizingwindowsforms.htm



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.