Start your first multilingual version of DOTNET applications (Winform)
Small gas god 2001-09-22
Multi-language version of the app is a threshold, and the past means it can face more users. For business programs, a localized version means that you might open a bigger market. The Chinese version was also a complex and expectation in our hearts about China. I hope that DOTNET can bring us different perspectives and changes, let us reopeize their software applications. Here I avoids two topics: localizing and globalization, one is a big topic, and their second seems to have become an important part of the software industry, and there is a professional process and practices.
The resource in the DOTNET has a new change than before, perhaps it is this change that makes a multi-language version of the application simple and feasible. However, there are still some bugs in the current VS.Net Beta2, sometimes there are some inexplicable errors, I believe that the next version of VS.NET will be more stable in this regard.
Ok, let us start from the easiest place.
1. Prepare a simple prototype application.
Here will be the simplest prototype for an application, there is not much logical and instructions, create a Windows Application's Project in VS.NET, just drag some controls to the form, then create a master to the form Menu, because I am using the English version of VS.NET, so this prototype is English version.
2. Add other resource to applications
This step, I add a picture resource to an external resource file, this picture will be displayed in a picturebox, actually set the image of the control directly when designing, but I want to assume that this picture is different later. Different pictures are displayed in the language version, of course, in this resource file I also added a string resource used to display usage.
Honestly, this version of the VS.Net has no resource tool with visualization. It actually causes the resource's modification and display in XML Designer View, and some pure characters can be made. If it is an image resource, I would rather use the SDK. Reseditor, (but you need to compile it into EXE in advance, it is generally in the / Samples / TutorialIals / ResourcesAdlocalization directory in your framework SDK installation directory). Specific can do this in vs.net: Project- > Add new item-> templates-> assembly resource file, first named myResource.resx. Default This file is the build action property of this file is Embeded Resource (with an IL DASM figure in Zip), you can see it) Starting ReSeditort Add a picture and a string resource, then save the ReSeditor. Here is how the resources in this external resource file are used in the program. You can use the code below:
Dim Res as system.resources.resourceManager
Res = New Resources.ResourceManager ("English,", me.gettype (). Assembly
strmsg = res. maxString ("msghello")
Me.Picbox.Image = ctype (res.getObject ("DotNetLogo"), System.drawing.Image
The above code demonstrates the code you get the resources and use the image resource and character resources. English: MyResource is the name of our exterior resource file, EnglishandChinese is our application or the name of Project. Res. maxString ("msghello"): Msghello is an NAME item in an external resource, thereby obtaining a string resource.
GetObject ("DOTNETLOGO") demonstrates that we will get the picture resource for Name of DotNetLogo in an external resource.
Now F5 is running, we can see the picture in PictureBox to display GetObject ("DotNetLogo"), and then the string of Res.getstring ("Msghello") is displayed in the pop-up messageBox box after pressing a button.
3. Turn our application into other language versions.
Here is two steps: First, the UI displayed in the simple WinFrom is turned into other language versions; the second is to turn our Myresouce to other language versions. For the first step, we can first click on the entire form. Check other language versions such as Chinese-Simplified attributes in the form of the form, locatlizable properties Select TRUE, then store the board; the menu, control on the form The text is changed from English to the Chinese font. Then save the disk F5 you will see the Chinese version of the application is displayed. You can also set the list of the form to (default), locatlizable is set to false, then you can see the original English version of the interface. At this time, F5, you will see the English version of the app. The current VS.NET Beta2 is unstable when the design view of the English and Chinese version is in the future. Sometimes a control on the form suddenly does not have or the form designer can no longer display the design form. In short, not very stable.
The second step will turn myResource to a multilingual version; still select Project-> add new item-> templates-> assembly resource file but this time the file name is: MyResource.zh-chs.resx, the same image In the second step, add new resources in the resource file, but the NAME name in the resource must be the same as the English language, the string called Msghello, the image resource is called DotNetLogo, OK rear repository. It is basically completed for preparation.
4. Some of the corresponding settings and tests.
Here is mainly some and code-related stuff, first write two basic small functions in the form:
Private function my_createresouce () AS Integer
'Handling your own resource file
Dim Res as system.resources.resourceManager
Res = New Resources.ResourceManager ("English,", me.gettype (). Assembly
strmsg = res. maxString ("msghello")
Me.Picbox.Image = ctype (res.getObject ("DotNetLogo"), System.drawing.Image
END FUNCTION
Private function initregistry () AS STRING
Dim akey as registryKey
DIM STRCURRLANGUAGE AS STRING
Akey = registry.currentuser.createSubKey (RegistryKeyForccboy) if Akey.getValue ("Language" is nothing then
Strcurrlanguage = "EN-US"
Akey.setValue ("Language", Strcurrlanguage)
Else
Strcurrlanguage = akey.getvalue ("Language")
END IF
INITREGISTRY = STRCURRLANGUAGE
END FUNCTION
The following code is then added to the new () function of the Form.
Public Sub New ()
Mybase.new ()
'This Call is Required by the Windows Form Designer.
DIM TMPCULTURE AS STRING
Struiculture = thread.currentthread.currentuicultuicultuiculture.displayName
Tmpculture = initregistry ()
Thread.currentthread.currentuicultuiculture = New CultureInfo (TMPCulture)
InitializeComponent ()
'Add anyinitization after the initializecomponent () CALL
End Sub
Don't forget to join the namespace below:
Imports system.globalization
Imports system.threading
Imports Microsoft.Win32
The above code completes the selection of the initial language version of the application and stores this information in the registry. Finally, use the two menu items of the main menu menu to set the selected feature of the language version.
Private sub menglish_click (Byval E AS System.Object, byval e as system.eventargs) Handles Menuitem4.click
'ENGLISH
Dim akey as registryKey
Akey = registry.currentuser.opensubkey (RegistryKeyForccBoy, true)
Akey.setValue ("Language", "EN-US")
End Sub
Private Sub Menuchinese_Click (Byvale AS System.Object, ByVal E As System.Eventargs) Handles Menuitem5.click
'CHINESE
Dim akey as registryKey
Akey = registry.currentuser.opensubkey (RegistryKeyForccBoy, true)
Akey.setValue ("Language", "ZH-CHS")
End Sub
Save your Project, F5 run. Then select the Chinese or English in the menu to start after quit. Here is the screen diagram of running:
supplement:
Current VS.NET Beta2 Converts Switching in Multi-language Switch Some problems, in practice, you can make this method; first complete an English version, then use the beta2 sdk tool resGen to convert Form1.RESX to Form1 .resources file, (Resgen form1.resx form1.resources) then open this converted Form1.Resources file with the Beta2 SDK new winres.exe, you can see the same form as the vs.net (the examples mentioned above Some inconsistencies, such as menus, then modify these UI fonts and expressing the language you need, select Save As .. Select your corresponding language in the pop-up dialog box. DOTNET allows you to add other different language versions after completing the entire app, as long as you place your language resource DLL according to DOTNET specification, your program can turn into any language version. For the second step in the second step in the second step, it is actually a STATELITE Assembly if the Strong Name is not available in the GAC, so it can only be placed in the directory specified by the DOTNET resource specification. However, it is similar to how many language methods, you can convert the RESX file with the above method, or create a resource file. In the current point of view, VS.NET and handmade is effective, the total point: The current DOTNET has a very common and standardized approach for multi-language versions, which is very different from it. There is also Beta2 present in this regard, it is still not very stable (Haha), thank you, thank you for reading this article, I hope to help you. In addition, the DOTNET flag in the picture of Demo is coming from the MS website, so this logo copyright belongs to Microsoft, and this statement.