Multi Language Software
Softwarebuero Jollans
This is Tikiwiki v2.2 -Arcturus- © 2002–2008 by the Tiki community
Wed 08 of Sept., 2010 19:58 CEST
Multi-Language Add-In for Visual StudioSee also Quick Tour (Windows Forms)Activating the Multi-Language Add-InAfter you have installed the Add-In, there will be a new menu item in the Tools menu in Visual Studio.![]() This menu item activates the Add-In and shows it in a tool-window. You can dock this window at the side of the main Visual Studio window, or drag it into a tab group, like other tool windows in Visual Studio. It's probably best to place it at the bottom, in a wide format. ![]() Selecting a projectA Visual Studio solution may contain multiple projects. However, the Multi-Language Add-In always works with a single project. To get started, you must first select the project. There are two ways to do this.
Initialising the project for localization
The Add-In will now add two new files to your project.
Scanning the projectThe Add-In will now scan the project. This is performed in two phases:
Adding a second language
Some languages, such as German or French, are considered to be neutral languages. The regional variations, such as German(Germany), German(Austria), French(France) or French(Canada) are referred to as specific languages. You should always add the neutral language before adding a related specific language. If you do choose to add a specific language, the Add-In will give you the option of adding both neutral and specific languages or only the neutral language. After adding the second language, the Add-In will
Now we will take a closer look at the two grids. The controls gridTo see the controls grid, make sure that the controls tab at the bottom of the window is selected. The grid should look something like the following screenshot.![]() By default, the properties are shown in a hierarchical manner, showing the association of properties to controls. As an alternative, you can view the properties on each Form or UserControl in a flat list. To select this mode, click on the button on the toolbar and then select Flat list from the menu, as shown below:![]() The controls grid will then look something like the following screenshot. ![]() To enter a translation, simply click in cell and type in the new text. If you are able to translate the text yourself, this is the easiest way enter translations. If a text is shown in light grey, then it is the text which would be retrieved at runtime via the resource fallback mechanism. In general, if a text is not defined for a specific language (e.g. Spanish(Mexico)) then the text for the neutral language (e.g. Spanish) would be used. If this has not been defined, then the original text in the project would be used. The check boxes to the left of the property name indicates that the text has been selected for translation. By default, all properties which contain a non empty string are selected. In the screenshot above, you can see two menu separators with the text "-". It makes no sense to translate these, so we can deselect them by clicking on the check boxes. ![]() In fact, we never really want to see these properties again, so we can go one step further and hide them completely. To do this, we first click on the sun symbol at the left hand margin. The sun symbol is replaced by a moon symbol .![]() To actually hide the lines, click on the mask symbol on the toolbar . If you want the hidden properties to be shown again, click on the button on the toolbar and select ''Show hidden properties" from the menu.By default, properties containing empty strings are not shown in the grid. It very rarely makes sense to translate empty strings, so this if sensible setting. If you do want to see localizable properties containing empty strings, then you can modify this option in the settings dialog. To show this dialog click on the settings button on the toolbar. Details of this and other options are described in the online help file.The source code gridTo see the source code grid, make sure that the source code tab at the bottom of the window is selected. The grid should look something like the following screenshot.![]() As in the controls grid, you can select a string for translation by clicking in the checkbox to the left of the line number. In contrast to the controls grid however, none of the texts are selected automatically. When you click on a line in the source code grid, the corresponding line in the source code will be shown in the source editor. Alternativly, if you select a line in the source editor, which contains a string, you can locate this line in the source code grid by clicking on the goto line button on the toolbar.![]() When you select a string for translation by clicking on the checkbox, the Add-In will assign a string ID number to the text and insert a call to the function ml_string() into the source code. ![]() As you can see, this function has two parameters:
The exact format of the function ml_string depends on the computer language used in the project.
The function ml_string is implemented in the module mlstring which was added to the project from a template file (usually in the directory C:\Program Files\MultiLang2005\Templates). Once a string has been selected for translation, you can enter a translation simply by typing a new text into the grid. As with the controls grid, we also have the option of hiding texts which do not require translation. For example, none of the texts in the module AssemblyInfo.cs need to be translated. As before, we hide a string by clicking on the sun symbol at the left hand margin, which is then replaced by a moon symbol . At the same time, the comment //MLHIDE ('MLHIDE in VB.NET) is added to the end of the source code line, to mark it as hidden.![]() To actually hide the lines, click on the mask symbol on the toolbar . This works a little differently to controls grid. The hidden items are collapsed behind a new node hidden and you can view them at any time simply be expanding this node.![]() It is good practice to either select or hide every string in the project. If new strings are added to the source code, it is then much easier to find the new strings in the grid. Of course, you can also add the MLHIDE comment to lines in the source code editor. When the Add-In scans the project, it will automatically hide these strings. Filtering texts with regular expressionsIn many cases, you will be able to select, or alternativly hide, texts in the source code based on simple rules. For example you will probably not want to translate SQL strings, or the parameters to an event logging function. On the other hand, you will probably always want to translate the parameters to the MessageBox function.You can handle operations like this easily with the feature "Filter with regular expressions". You can select this option from the tools menu as shown below, or from the context menu in the source code grid. ![]() This command shows the filter dialog, in which you can enter a search string as a regular expression. For example in the screenshot shown below, the search string " ^ select " will search for any string starting with the word select, with the option to hide the string. ![]() The dialog offers the option to match only the string, or the complete source code line. By matching the complete code line, it is easy to detect strings used in particular function calls. When the string is found, the Add-In asks whether the specific string should actually be hidden. ![]() Using the translation memoryAside from the project database used to store the translations for an individual project, the Multi-Language Add-In also stores all translations in global translations database. When it detects an exact match between a new text and a translation stored in the global database, it will insert the translation automatically. This is great for common terms like OK and Cancel.If you are able to translate the texts yourself, then the translation memory provides an additional help, based on the translations stored in the global database. To use the translation memory, first click in the cell you want to edit, and then hit F3 or F12. The following screenshot shows the translation memory dialog with the text Add a new language to the project, which should be translated into German. ![]() In the lower part of the dialog, there is list of existing translations, containing one or more of the same words as the string to be translated. The list is sorted according to the number of matching words, so the most useful translations should be near the top. You can copy words out of the grid and edit the new translation in the edit box marked Translation. Obviously, the common words "a", "to" and "the" will not be of much help. If you select the tab Ignored words, you can select the words which are to be ignored. The Add-In keeps a list of ignored words in the global database and automatically ignores these words in future. The translation memory feature is particularly useful for technical terms where you might not be familiar with the correct translation and where you want to use terms consistently. Using the Spreadsheet exportIf you are not able to translate the texts yourself, you will have to give them to a translator. For this purpose you can use the Spreadsheet export/import feature. There are two versions of this feature:
on the toolbar.The screenshot below shows the format of the simple spreadsheet file. As you can see, the first column contains the string ID number, followed by a column for each language. The first two rows contain the language names and the locale ID numbers. ![]() The translator should update texts in the appropriate language column, without changing the format of the file. When the translator is complete, you can import the translations back into the project. The three worksheet format contains two additional worksheets, which closely resemble the controls grid and the source code grid in the Add-In. These worksheets provide more context information for the translator. Because all texts in the additional worksheets are also present in the third worksheet, Excel macros are used to maintain consistency within the file. The macros also provide some additional functionality, similar to some of the functions provided by the Add-In. The three worksheet is to be recommended, unless your organization is adamantly opposed to using macros. The Excel support requires that Excel be installed on the PC. The OpenOffice support uses the AODL Library and does not require that OpenOffice be installed. Exporting the texts to resource filesIn order for the translations to be used in your project you must:
![]() The satellite dlls must be distributed with your application and installed in subdirectories exactly as they are generated by Visual Studio. The compiled project is now localized. Windows will initialise the application to use the language of the Windows user interface. For example, if you have added support for German, and you install your application (with the satellite dlls) on computer running a German version of Windows, then German resources will automatically be used. Selecting the language of the applicationIt is very practical to be able to select the language for your application, independently of the language used by Windows. This is almost essential for testing, but you may also want to make it a permanent feature of your application. We must consider two cases separately:
Technically, it is very easy to set the language of a program when it starts up. It is only necessary to set the CurrentUICulture property of the main thread, before the main form of the program is called.
Changing the language of a running programA little more effort is required to change the language once the user interface of the program has been initialised. The problem breaks down into three operations:
|








































