Suppose that your project is already partly localized, using hand coded function calls to load resource strings and that you already have translations in multiple languages stored in resource files. If you decide start using the Multi-Language Add-In for .NET to localize your project, what will happen to the existing localization?
Starting with version 4.52.0003 the Add-In contains a special feature to import existing localization into the Add-In's project database.
This import performs two functions:
To identify the function calls which are used to load resource strings, you must define a regular expression. We will look at this later on with a couple of examples.
|
To access the import function, select "Import existing localization" from the tools menu. This will open the dialog shown below. The operation has two steps:
No changes are made to the project in step 1. |
|
|
At the top of the dialog are the two fields:
We'll look at the resource file first, because it is the easier one to understand. |
If your project contains multiple resource files, then you must select the file containing the translation to be imported. You can select the resource file from a drop down list, which contains all of the neutral language resource files in your project.
The list does not contain any language specific resource files or the local resource files used for Forms or UserControls.
If you need to import strings from more than one resource file, then you must perform the operation repeatedly.
The search pattern is defined using a regular expression. The syntax for regular expressions is defined in the Visual Studio Help, for the System.Text.RegularExpressions.RegEx class.
The regular expression must perform two tasks:
The resource name must be matched using the named grouping construct with the name param. The syntax for this is
(?<param> ... )
where ... represents the search pattern for the parameter itself. If the resource name is in quotes, then the quotes should not be part of the captured parameter.
Let's look at some examples:
In this example we want to detect the function calls to ResMgr.GetString() as shown
below:
| ListBox1.Items.Add ( ResMgr.GetString ( "Hallo" ) ) ListBox1.Items.Add ( ResMgr.GetString ( "Bye" ) ) ListBox1.Items.Add ( ResMgr.GetString ( "Not present" ) ) |
We can match these calls with the following regular expression
ResMgr\.GetString\s*\(\s*\"(?<param>.*)\"\s*\)
which contains the following elements:
| ResMgr\.GetString | This matches the function name ResMgr.GetString. The escape sequence "\." is required to match the literal character ".". |
| \s* | This matches any number of white space characters (0 or more). |
| \( | This matches the opening bracket. |
| \s* | This matches any number of white space characters (0 or more). |
| \" | This matches the opening quote. |
| (?<param>.*) | This matches any characters and stores the result in the named group "param". The group ends when the closing quote is detected. |
| \" | This matches the closing quote. |
| \s* | This matches any number of white space characters (0 or more). |
| \) | This matches the closing bracket. |
After specifying the regular expression, you can start the search operation by clicking on the "Search" button. The results will be shown in the grid, as below: