History: MLNetImportLocalization

Preview of version: 1

Importing existing localization in a .NET project

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:

  • it imports the existing resource strings into the project database and
  • it replaces the existing function calls with calls to the function ml_string()


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:
  1. Search, in which it searches for function calls in the source code
  2. Import, in which it imports the resource strings and converts the function calls.

No changes are made to the project in step 1.
Image Image
Image
At the top of the dialog are the two fields:
  • Regular expression as search pattern
  • Resource file

We'll look at the resource file first, because it is the easier one to understand.

Selecting the resource file

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.

Defining the search pattern

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 syntax supported by System.Text.RegularExpressions.RegEx class differs slightly from syntax supported by the Visual Studio Editor. In particular, the format "\s" for any whitespace character does not seem to work in the editor!

Matching the resource name

The regular expression must perform two tasks:

  • it must match the complete function call, identifying the exact text which has to be replaced and
  • it must match the parameter specifying the resource name, using a grouping construct.


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:

Example 1

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\.GetStringThis 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:
Image





History

Information Version
Sun 02 of Mar, 2008 15:06 GMT Phil 5
Sun 02 of Mar, 2008 15:00 GMT Phil 4
Sun 02 of Mar, 2008 14:55 GMT Phil 3
Sun 02 of Mar, 2008 14:47 GMT Phil 2
Sun 02 of Mar, 2008 14:17 GMT Phil 1