• mohit vashistha

Localizing WPF application

Localization of application using .NET tool required following steps (taken from https://wpf.2000things.com ):


Step-1 : Mark assembly’s UI culture. 2

Step-2 : Add UID to localizable elements: 2

Step-3 : Updating UIDs after Initial Creation. 3

Step-4 : Get LocBaml Tool 4

Step-5 : Extracting Localizable Content Using LocBaml 5

Step-6 : Interpreting CSV File That Is Output by LocBaml Tool 5

Step-7 : Preventing Translator from Modifying Certain Elements. 6

Step-8 : Passing Comments On to the Translator. 6

Step-9 : Integrating Translations Back into Application. 7

Step-10 : Add Content to Already Localized Application (on-going process). 7

Step-1 : Mark assembly’s UI culture

Step-2 : Add UID to localizable elements:

After adding a UICulture tag, the next step in localizing a WPF is to assign a UID (unique identifier) to each element in each of your XAML files. These UIDs will later be used to localize/translate the XAML.

To start, press the Windows key, type Visual Studio, and click on the Visual Studio Tools icon.

Double-click the Developer Command Prompt for VS2013 shortcut.

In the command prompt, navigate to the directory containing your project (.csproj) file. Enter the command:

msbuild /t:updateuid [yourapplication].csproj

Open your project and then open one of your .xaml files. You’ll see that each element now has a x:Uid attribute that wasn’t there before. Each element will have a unique value for this attribute.

Before running msbuild:

After running msbuild:

Step-3 : Updating UIDs after Initial Creation

In order to localize your application, you must assign unique UIDs to all elements. This is done with the msbuild command and the /t:updateuid parameter. You normally do this before you start localizing your application.

If you later add user interface elements to your application, you’ll have some elements that don’t have the x:Uidattribute. You can check to see if there are elements that are missing this attribute using the /t:checkuid parameter on the msbuild command.

At this point, you can use the /t:updateuid parameter with the msbuild command again to add the x:Uid attribute to any elements that are missing it. This command will also fix any duplicated UIDs.

You can use the /t:updateuid parameter as often as you like. Each time you run msbuild with this parameter, you’ll update UIDs for all user interface elements.

Step-4 : Get LocBaml Tool

After generating UIDs for all user interface elements in your project, the next step is to extract elements that need to be localized (i.e. given values for a specific language) into an external file. This file can be passed to people doing the localization.

To extract localizable data, you need a tool called LocBaml. This tool is made available by Microsoft, but not distributed with Visual Studio.

To get a copy of the LocBaml tool:

1. Download LocBaml project (for .NET 4) from here

2. Open LocBaml project and rebuild using Release|x86 configuration, targeting a .NET Framework version that matches your main project

Step-5 : Extracting Localizable Content Using LocBaml

Once you’ve generated UIDs for user interface elements and obtained the LocBaml tool, the next step in the localization process is to extract localizable content from the BAML data in your compiled DLL.

The steps are as follows:

1. Copy the locbaml.exe into the same directory as your application’s .exe file

2. Open a Visual Studio 2013 command prompt

3. Navigate to directory containing your .exe (e.g. \bin\Release, with \en-US sub-directory containing satellite assembly)

4. Enter: locbaml.exe /parse .\en-US\[application].resources.dll (where en-US is the default culture)

After running this command, you’ll see a .csv file show up in the same directory (e.g. WpfApplication1.resources.csv). The CSV file will contain a list of localizable content.

Step-6 : Interpreting CSV File That Is Output by LocBaml Tool

As part of the localization process, you can use the LocBaml tool to extract localizable content into a text-based .csv file.

Below is a snapshot of a sample .csv file containing localizable content.

Each line in the .csv file represents a single property of some user interface element. The line contains the following elements (separated by commas):

1. The name of the BAML resource containing the property

(e.g. WpfApplication1.g.en-US.resources:mainwindow.baml)

2. Fully qualified property name, including the element’s UID (e.g. Label_1:System.Windows.Controls.ContentControl.Content)

3. Localization category (e.g. Button, Label, Text, etc).

4. Whether property is visible to user (T/F).

5. Whether property can or should be modified by translator (T/F) (defaults to true for all elements)

6. Comments provided for translator (defaults to blank)

7. Property value (the thing that should be localized)

Step-7 : Preventing Translator from Modifying Certain Elements

By default, when a .csv file is created using the LocBaml tool, the fifth parameter on each line is set to True. This parameter indicates whether a particular property should be modifiable by the translator.

You can change the value of this modifiable field by setting the Localization.Attributes property for an element. This property is set to a string of the form “propname(locvalue1 locvalue2) propname(locvalue1 locvalue2)”.

One of the localizability values that you can set is Unmodifiable, to indicate that the specified property should not be modified by the translator.

Below, we set Unmodifiable for various property values.

After running the LocBaml tool, we see that the modifiable field is now false for these properties.

Step-8 : Passing Comments On to the Translator

When you have an application that will be localizable, you use localization attributes to explicitly mark which elements need to be localized. You may want to also add a comment for a particular element, to help the translator in localizing the content.

You can add a comment for the translator in a XAML file using the Localization.Comments attribute. The property can contain comments for multiple attributes and the comments will be written to the .csv file with the corresponding attribute.

Below, we specify a comment to be associated with the Content property.

Now, after generating the .csv file with LocBaml, we see that the comment shows up.

Step-9 : Integrating Translations Back into Application

Once you get localized resources back from the translation team, you need to integrate these localized resources back into your application.

To integrate localized changes, once you have the new .csv file containing localized resources, do the following:

1. Open a Visual Studio command prompt

2. Change directory to be directory containing main application .exe file (e.g. \bin\Release)

3. Copy .csv file containing translations into this directory (e.g. WpfApplication1.resources.fr-FR.csv)

4. Create a sub-directory matching the desired culture name (e.g. fr-FR)

5. Ensure that locbaml.exe is also present in this directory

6. Execute this command: locbaml.exe /generate .\en-US\WpfApplication1.resources.dll /trans:.\WpfApplication1.resources.fr-FR.csv /out:.\fr-FR /cul:fr-FR

7. You should see a new WpfApplication1.resources.dll file in the fr-FR sub-directory.

Step-10 : Add Content to Already Localized Application (on-going process)

After localizing your application for multiple languages, you have a main executable and a satellite assembly for each language that you’ve localized for.

If you then make changes to content in your application that is represented as XAML, the changes will show up in the satellite assembly for the neutral language, but not in the other satellite assemblies. The changes will only be present when running under the neutral language.

After changing XAML content in a localized application, you need to take the following steps:

1. Make changes in Visual Studio, fully test under neutral language

2. Update UIDs using msbuild tool: msbuild /t:updateuid appname.csproj

3. Save and rebuild application

4. Re-extract localizable content using LocBaml tool: locbaml.exe /parse .\en-US\appname.resources.dll

5. Localize new content, integrating changes into existing language-specific .csv files

6. Re-generate satellite DLLs using LocBaml: locbaml.exe /generate .\en-US\appname.resources.dll /trans:.\appname.resources.fr-FR.csv /out:.\fr-FR /cul:fr-FR

7. Run application and test changes

6 views0 comments