RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Globalize and Localize Your "Avalon" Applications Using LocBaml : Page 4

You already know that internationalizing your applications can propel you into new markets. But did you know that the Windows Presentation Framework can make it easier than ever to do? Learn how to write culture-aware WPF applications using this example.

Localizing the Content
To use the LocBaml tool to extract the text content from the resource file, type the following in the Release Build Environment command window:

C:\LocBaml\CSharp\bin\Debug>locbaml /parse c:\WPF\bin\en-US\WPF.resources.dll /out:c:\WPF\text.csv
A file containing multiple columns of comma-separated fields is saved in the file named text.csv. You can double-click it to view it in Microsoft Excel (see Figure 11). This file contains all the text content (and other information) used in the application.

Each row in the file contains seven fields separated by a comma, with the following field names:

[Baml Name],[Resource Key],[Localization Category],[Readable],[Modifiable],[Comments],[Value]
In particular, to change the text content of the application, you need to modify the last field, changing its contents from English to your target lanugage. You can also use Notepad to view the Text.csv file, as I've done in Figure 12. It shows three lines from the file. At the end of each line, I've replaced the Value field with the appropriate Chinese characters; these will be displayed in the UI.
Author's Note: There is a variety of ways to enter Chinese characters: Windows XP includes Chinese support or you can use a third-party tool. This link offers explicit instructions on Chinese language input.

Figure 11. Application TOC: Using the Text.csv file, you can read all the contents of your application in one place.
Figure 12. Translation: Here, the contents of the last field from text.csv have been translate to the corresponding Chinese characters.

Once you are done with the translation, save the file as Text1.csv (remember to save the file as a Unicode text file, or else you will lose the Chinese characters).

Create a new folder called "zh-CN" in C:\LocalizedWPF\LocalizedWPF\bin\. This will store the localized (Chinese) resources for the application.

To generate the localized resource file from the Text1.csv file, type the following command using the LocBaml tool:

C:\LocBaml\CSharp\bin\Debug>locbaml /generate c:\WPF\bin\en-US\WPF.resources.dll
 /trans:c:\WPF\text1.csv /out:c:\WPF\bin\zh-CN\ /cul:zh-CN
A resource file will now be saved in the C:\WPF\bin\zh-CN\ folder.

You can now test the application by pressing F5 in Visual Studio 2005. Change the culture to "Chinese (People's Republic of China)" and restart the application. The right panel of the application window will display the Chinese characters (see Figure 13).

Figure 13. Eastern Exposure: The finished application, translated to Chinese, is shown.

The chief advantage of extracting the text content from resource files using the LocBaml tool is that it allows you to leave the translation process to the real language expert, not the programmer.

In this article, you have learnt how to localize a WPF application using the LocBaml tool. Using the LocBaml tool, you can concentrate on building your WPF application and then perform the localization at a later stage. Let me know if you encounter any issues in using the LocBaml tool.

Wei-Meng Lee is a Microsoft MVP and founder of Developer Learning Solutions, a technology company specializing in hands-on training on the latest Microsoft technologies. He is an established developer and trainer specializing in .NET and wireless technologies. Wei-Meng speaks regularly at international conferences and has authored and coauthored numerous books on .NET, XML, and wireless technologies. He writes extensively on topics ranging from .NET to Mac OS X. He is also the author of the .NET Compact Framework Pocket Guide, ASP.NET 2.0: A Developer's Notebook (both from O'Reilly Media, Inc.), and Programming Sudoku (Apress). Here is Wei-Meng's blog.
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date