Lingobit Localizer - Software Localization ToolTools for software Localization DE | DA | FR | ES | IT | JA | NL | PL | PT | RU | TR | ZH
Software Localization

Lingobit Home > Solutions

WPF, XAML and BAML Localization

WPF localizationLingobit software localization tool provides you with productivity tools for WPF, XAML and BAML localization making it as easy as never before

Windows Presentation Foundation (WPF) is the graphical subsystem feature of the .NET Framework 3.0 and is directly related to XAML. Microsoft introduced localization approach for WPF localization, but it happened to be very burdensome.

WPF localization is much more easer with Lingobit software localization tool. It extends Microsoft approach for WPF localization by automating the most cumbersome steps and providing full control over translation process.

Lingobit Localizer translates compiled executable files and creates satellite assemblies for each translated language.

How it works: WPF BAML Localization

When you localize a WPF application, you have several options. For example, you can bind the localizable resources in your application to an XML file, store localizable text in resx tables, or have your localizer use XAML files. Lingobit Localizer supports all approaches. Here we'll discuss WPF localization workflow that uses binary XAML (BAML).

After WPF application is compiled, it contains two types of resources

  • Typical .NET resources compiled from ResX files named MyApp.Properties.Resources.resources. You can read about it at .NET localization page.
  • WPF resources named MyApp.g.resources.

WPF BAML localizationWPF resource section contains files that are used in WPF code: images, web pages and BAML files. BAML is a compiled XAML that stores WPF user interface. Lingobit Localizer extract localizable resources from BAML files and allows you to translate them. After application is translated, Lingobit Localizer creates satellite language assemblies for each translated language.

WPF, XAML and BAML software localization

Prepare WPF for localization

Setting Uid

How to prepare WPF application for localizationBefore localizing WPF application you need to add Uids to your XAML files. Uid properties are needed in order for Microsoft WPF localization APIs to work correctly. Uids are used to keep track of changes to files and to identify items that must be translated. To add Uids to your files, run updateuid on your project file.

msbuild /t:updateuid MyProject.csproj 

This is the recommended method of adding Uid properties because manually adding them is typically time-consuming and less accurate. You can check that Uid properties are correctly set by running

msbuild /t:checkuid MyProject.csproj.

After running updateuid, your files should contain Uids. For example, in the Page1.xaml file of MyApp, you should find the following:\

<StackPanel x:Uid="StackPanel_1">
  <TextBlock x:Uid="TextBlock_1">Hello World</TextBlock>

XAML xml:lang property

Notice the xml:lang placed at the root element of the XAML file. This property describes the culture of a given element and its children. This value is used by several features in WPF and should be changed appropriately during localization. This value changes what language dictionary is use to hyphenate and spell check words. It also affects the display of digits and how the font fallback system selects which font to use. Finally, the property affects the way numbers are displayed and the way texts written in complex scripts are shaped. The default value is “en-US”.

Silverlight localization

Lingobit Localizer can be used for Silverlight localization. You can read about it at Silverlight Localization page.

Language-neutral assembly

In the project file you can set <UICulture>en-US</UICulture> so that when the application is compiled, a language-neutral main assembly is generated. This assembly has a satellite .resources.dll file that contains all the localizable resources. Optionally, you can keep the source language in the main assembly because our localization APIs supports extraction from the main assembly. When the file is compiled, the XAML is converted to BAML. The culturally neutral MyApp.exe and the culturally dependent (English) MyApp.resources.dll files are released to the English-speaking customer. Note: if you set UICulture option, you must set the same Original language for Lingobit Project.

Localizing WPF application

After the application is configured, build your application and add your compiled files into Lingobit Localizer project. Lingobit Localizer empowers you with all its localization features, leaving aside cumbersome LocBaml CSV editing. WPF Localization tool provides you with translation change control, visual preview of translated user interface, translation management and many other productivity tools. You can test WPF localization sample the is distributed with Lingobit Localizer.

Configuring WPF localization parser

There are a lot of configuration properties that can be used to localize you WPF application. Here are links to MSDN info on these topics

You can define values for each element in XAML or you can set some properties for all class instances in your application code.

Lingobit Localizer allows you to configure parser to filter WPF properties, localization categories and localization attributes. When parsing file, values from XAML have more priority, than values requested from object type.

Best Practices for WPF UI Design

When you design a WPF–based UI, consider implementing these best practices:

  • Write your UI in XAML; avoid creating UI in code..
  • Avoid using absolute positions and fixed sizes to lay out content; instead, use relative or automatic sizing.
    • Use SizeToContent; and keep widths and heights set to Auto.
    • Avoid using Canvas to lay out UIs.
    • Grid and its size-sharing feature.
  • Provide extra space in margins because localized text often requires more space. Extra space allows for possible overhanging characters.
  • Enable TextWrapping on TextBlock to avoid clipping.
  • Set the xml:lang attribute. This attribute describes the culture of a specific element and its child elements. The value of this property changes the behavior of several features in WPF. For example, it changes the behavior of hyphenation, spell checking, number substitution, complex script shaping, and font fallback. See Globalization for the Windows Presentation Foundation for more information about setting the xml:lang Handling in XAML.
  • Create a customized composite font to obtain better control of fonts that are used for different languages. By default, WPF uses the GlobalUserInterface.composite font in your Windows\Fonts directory.
  • When you create navigation applications that may be localized in a culture that presents text in a right-to-left format, explicitly set the FlowDirection of every page to ensure the page does not inherit FlowDirection from the NavigationWindow.

Best Practices for WPF Localization

When you localize WPF–based applications, consider implementing these best practices:

  • Use localization attributes to control localization instead of selectively omitting Uid properties on elements. See Localization Attributes and Comments for more information.
  • Use msbuild /t:updateuid and /t:checkuid to add and check Uid properties in your XAML.
    • Do not edit or change Uid properties after you begin localization.
    • Do not use duplicate Uid properties (remember this tip when you use the copy-and-paste command).
    • Set the UltimateResourceFallback location in AssemblyInfo.* to specify the appropriate language for fallback (for example, [assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]).
    • If you decide to include your source language in the main assembly by omitting the <UICulture> tag in your project file, set the UltimateResourceFallback location as the main assembly instead of the satellite (for example, [assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.MainAssembly)]).


Other .NET localization platforms

.NET Framework has several technologies that use slightly different approaches for localization. Please select the one you need