With little effort and Visual Studio 2005 it is really easy to create applications that use localized resources. In this article I will create a small utility in C# localized, which will also allow you to carry a record of internet connections and their duration
Every programmer knows how tedious that might be translating an application into another language, especially the difficulties of organizing the entire interface to conform to the new interface. How can be simplified to the maximum this process? How can I distribute the translation work? How incorporate new localized resources?, all these questions will have a simple answer in this article.
For a few days I investigated procedures for translating applications in Visual Studio and as I couldn't find a tutorial that explain this task really easy, I decided to write this article.
In the Visual Studio 2005 version, as we shall see below, the work are incredibly simplified. Specifically the application as will generate This article will have intended use the resources in Windows (NT, 2000, XP, 2003 or Vista) to filter certain data and deliver useful information.
System will store a series of events in a database which can be called from the start menu, typing "eventvwr.msc". Among these events, in the field of system events, there is a series of events that indicate connections or disconnections made via a modem. If for any reason you have a connection charged for minutes, hours, or simply want to take a record of your connections could review this list and filter important events:
The purpose of the application then will be organizing this information "already existing" useful purposes:
To simplify things, between Visual Studio libraries are implemented the instructions to access those resources.
First, the program in our language
Quickly create the application forms, the main form will look similar to the following:
and another child form:
The main procedure of the application in this case is that access to the system event and filters the data. Only the events of 'system' of the current user, the default category (connection events, the identifier, called will be considered InstanceId(, these events can be seen directly in Event Viewer or to debug cycle that provides access to them) and are within the range of dates specified by the user:
Important to "locate" applications
Something that can not miss in the process is the linkage with resources. For forms and controls it is not necessary, because Visual Studio will subsequently be responsible, yet for all that apply to internal networks is very important.
This task is quite simple, consider a typical code that writes a message in the status bar to illustrate the idea:
This is hardly locatable, can you imagine to be changing messages that way? What happens with languages that do not have the same structure for certain phrases?
With a little more effort could write something more elegant:
This looks much better. Finally with the Visual Studio Resource Manager we were able to:
Our application is now ready so that we begin to translate it as properly using resources achieved independence the same language code and the message itself.
Do you understand me?
Many people will not believe it, but start to translate all the dialogues (in this case from Spanish to English) simply have to change two properties of the form:
So, without more, simply devoted to translate the form directly replacing the appropriate properties, for example "Text" for the buttons:
Then, Visual Studio will generate a resource file for translation. Resource files generated are based on the following template names:
< form name >. < location > .resx
I.e., for "FormMain" form, in English of our program resources are stored in:
We could even make different versions, for example the version to "English (United States)" will be:
For the original resources (in Spanish) is used:
Simply duplicate the original resource file and rename the compiler to include it as localized resources, although, as I said earlier, this procedure is fully automatic for forms and controls when the form has enabled "Localizable" property.
Explanation of the location
Once all resource, one for each location, files are generated, we compile the application. The compilation process will create a folder by location (except for the default, which is integrated into the application):
When an application (in this case, with the name of executable "app") with elements "localizable" (as configured in the previous point) starts on a computer with Windows in English in the United States ("en-US"), then:
Then, and the remaining strings
After the previous explanation, I think that it is simple to imagine how to translate the text strings that are not of form, but code controls. Previously, I gave an example code using resources, the real statement in C# is:
Of course you can touch up:
Where < app > is the name of the project and < resource > is the text string that identifies the resource. After creating resource files with the languages:
We translate the final chains that were not directly within a form:
Those "localized" file management will be managed automatically at the beginning of the application as previously noted in the previous point.
Distribute the translation work
To be able to dose the translation of resources work can use small tool "WinRes.exe" (included in the installation of Visual Studio) and in this way anyone can translate the resource file without Visual Studio installed:
By default, the resource editor is located in the folder
Testing and checking translations
After compiling a file with resources localized clearly we want to check that everything works properly. The less practical but more simple way is simply to run the application in a suitable operating system (for example Windows XP in English).
Another way is to install a language pack for our current system, available for the professional versions of them by Microsoft.
The last way is simply by adding the following line of code to the application (in the "Main" procedure):
In where < id_lenguaje > refers to the identifier, e.g. "es-CL" for Spanish (Chile) or "en-US" for English (United States).
Compile and run the application to forcing the load of certain localized resources.
Source code and binaries
Source code and binaries updated 26/01/2007
Changes and new features in the version 188.8.131.52:
-The duration of each connection is now displayed as hh: mm: SS, formerly h: m: s
-To change the date range, the list is updated automatically
-Now you can compile correctly on any computer
-Export button in the main dialog
-Icons in the main function buttons
-Cost calculation window now reflects the changes instantly
-Export selection is disabled when there is no selection
-Events can be exported
-Window remembers its position and size
As always can not miss the resources used in the course of this article as either the executable file of the same application:
Some interface elements rely on the regional settings as well as the configuration language and locality of the equipment, for example the hours and in this case the date format.
This means that the implementation of the programme with resources in English does not necessarily affect the date format settings YYYY-MM-DD. However these parameters (global team) can be configured in the control panel according to the preferences and needs of the users
Download the executable:
The executable code package includes, in addition to resources in English, a XML configuration file.
It is also recommended to increase the size of the registry, by default the limit can prevent that the registration extends more than one couple of days, from Event Viewer, in the system event log properties can be configured a new value for the size and duration of the same.
Download the source code (C#, VS2005):
Two related objectives: allow the use of "hidden information" for purposes useful to generate a log of connections (code that can be modified easily for any other purpose related to the "events") and learn how easy that might be locating our application.
Related to the theme of location I can draw some additional conclusions:
-Plan the development well before writing any line of code, especially code that involves strings that must be translated.
-Never start translation of parts that are not completely finished.
-Prepare good music, translating things is very tedious even in extremely tiny developments like the present.