BackgroundLocalizing a WPF application is not an easy task. Almost any article on the localization of WPF is replete with details and manual steps toimplementation a localized application.
Existing solutionsLocalization using the utility LocBaml are described in the localization of Microsoft has lots of advantages, but difficult to maintain. André van heerwaarde in his article proposed to simplify this decision by the configured build step. He wrote an utility to merge the translated text fragments. However, in his article, still many manual steps.
Visual Studio Project TemplateI propose to use a Localized WPF Application template, I've created to start working on a multilingual WPF application. Project created using this template already contains all the necessary tools for localization, as well as the maximum automates the localization process.
During application development, you add a new XAML file without having to worry about localization. Upon completion of the changes simply build project.
- Custom build step will call msbuild / t: updateuid [Project Name].csproj. This step will automatically add x:Uid at every element containing the text elements.
- Then in the build process will start automatically LocBaml, which finds all text elements in the XAML file and generates a CSV file containing the text elements.
- The next step will run the utility from MergeLocBamlCsv André van heerwaarde. As a result, earlier translated segments will be merged with the new.
- Utility StripLocBamlCsv Cut unused items from the CSV file.
The only thing you have to do manually is to add new languages and the actual translation itself.
Adding a new languageTo add a new language in the draft you will have:
copy the location of the neutral language in the new CSV file
copy Translation\Translate.csv Translation\Translate.ru-RU.csv
open the project file in a text editor and after lines:
add a new language, for example:
Then you need to reopen the project in Visual Studio, if the project was already open, the IDE will ask whether you wish to reopen the project to reflect the changes, answer 'Yes'.
If you did not make mistakes, then the newly open project folder Translation will be a new file Translate.ru-RU.csv
Start the assembly to update the translation files, then you can open a new file and start translating.
Localize text in code behindStringResources.xaml is a Resource Dictionary example for translated strings:
<ResourceDictionaryUsage as easy as:
<!-- String resource that can be localized -->
this.Title = (string)FindResource("MainWindow");
Links and credits
WPF Localization Guidance
WPF Globalization and Localization Overview
LocBaml + MsBuild + ClickOnce Deployment
Localizable WPF Project