1. Install the add ins (if VS is open, you need to close and reopen).

2. Choose a project or a xaml file, and go to the tools menu.

The dialog appears :
Choose your method :
  • {Binding} Method : change your XAML file to replace text by {binding} and export the text to resx file.
  • by code : export the text to resx file, create a c# file with a new method Translate, this method is experimental (no support of template resources for example) (the xaml file is unmodified except options below).

Include : Something cryptic for now, but the synthax is the fullname;properties to scan,....

Exclude : Same synthax as include.

Resource Generator : If you use the {binding} method, we need a resx code generator with public member and public constructor (the default public generator of VS creates an internal constructor) => for now, i use ... but you can use other.

Try to convert content node to text/content attribute : It seems that a lot of WPF code does not put Content on attribute but in content element. If you activate this option, the tools try to convert content element to content attribute.
Example : <CheckBox x:Uid="CheckBox1">Text text</CheckBox> => <CheckBox x:Uid="CheckBox1" Content="Text text" /> and then apply code/binding method.
Work for System.Windows.Controls.Label, System.Windows.Controls.ComboBoxItem, System.Windows.Controls.CheckBox, System.Windows.Controls.RadioButton, System.Windows.Controls.TextBlock. Only work with simple content with no carriage return and no element.

Create name attribute (code method) : It creates name attribute if necessary. The code method needs member in class (somebody has found a way to find element by uid in runtime ?).

3. For each selected XAML file, or for each XAML file in project, the tools creates a resx file in the subdirectory App_Resources, launchs the custom tool on each resx file (only binding method) (=> create designer file), creates a xx.translat.cs file (only code method) under the xaml file. If is the first time, it can take some time (like 10 sec/XAML, it is independant of the power of your machine, it is a problem with VS to add new files to solution).

If you use the code method, do not forget to call Translate method after InitializeComponent, thus you need to modify your constructor.

Creating resx file is only a part of the localization process.

You have a tools that creates localized resx file, how to add the localized resx file to the application and how to use in runtime.

The described method is to include the resource in .xap for silverlight application (seems there is other method to keep resource in external dll, i will check this another day).

Check http://silverlightlocalize.codeplex.com/

Adding a new culture to your proj.

This steps must be repeated if you add a new language.

In solution explorer unload your project

Then edit your project

Search a line like :
Add your language :
Multiple culture are separated by ";". Do not add the "default" culture.

Save your project

Reload project

Adding the resx file to your proj.

This steps must be repeated if you add new resx file.

Click Show All File for your project.

Select your new resx file and Include them in project.

Choose and change language in application

There is a lot of method to do that :
1) The magic line code :
Thread.CurrentThread.CurrentUICulture = new CultureInfo("nl-BE");
You can use in Application_Startup code.
(do not forget to change Thread.CurrentThread.CurrentCulture if you need to "globalize" your application (decimal separator, date format, ...) )

You can change latter, but
if you use bindings, you need to reload your page/usercontrol (for example this.RootVisual = new xxx() ).
if you use code method, you need to call Translate (eventually other method to refresh your display)

2) Passing parameter when you construct the silverlight control :
<param name="uiculture" value="nl-BE" />
(do not forget to add eventually culture param for globalization)
(you can change this if the page is dynamic (.aspx page)).

Update App.xaml.cs, copy the following code to the Application_Startup method
string cultureName;
if (e.InitParams.TryGetValue("UICulture", out cultureName))
if (!String.IsNullOrEmpty(cultureName))
Thread.CurrentThread.CurrentUICulture =
new CultureInfo(cultureName);


To translate complex text like :
<TextBlock>Multiples lines<LineBreak />Multiples lines</TextBlock>
You need to enclose text in <Run> tag.
<TextBlock><Run Text="Multiples lines"/><LineBreak /><Run Text="Multiples lines"/></TextBlock>
(it is not really a overhead because the runtime does this conversion)

Old BAML Convertion

If you use in the past BAML, do not forget to edit your project file to remove the content of <UICulture> and change fallback as default main assembly (and it is normal that your localized dlls become "rikiki" because they contain only the translation not the full XAML as before).

Last edited Dec 28, 2009 at 12:49 PM by Cestbienmoi, version 11


No comments yet.