Best Practices for Globalization and Localization in WPF


You can make the most of the globalization and localization functionality that is built into Windows Presentation Foundation by following the UI design and localization-related tips that this section provides.


Best Practices for WPF UI Design


When you design a Windows Presentation Foundation–based UI, consider implementing these best practices:





  • Write your UI in XAML; avoid creating UI in code. When you create your UI by using XAML, you expose it through built-in localization APIs.



  • 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.



    • Use 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.



  • Create a customized composite font to obtain better control of fonts that are used for different languages. By default, Windows Presentation Foundation 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.



  • When you create stand-alone navigation applications that are hosted outside a browser, set the StartupURI for your initial application to a NavigationWindow instead of to a page (for example, <Application StartupUri=”NavigationWindow.xaml”>). This design enables you to change the FlowDirection of the Window and the navigation bar.


Best Practices for WPF Localization


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





  • Use localization comments to provide extra context for localizers.



  • Use localization attributes to control localization instead of selectively omitting Uid properties on elements.



  • Use msbuild /t:updateuid and /t:checkuid to add and check Uid properties in your XAML. Use Uid properties to track changes between development and localization. Uid properties help you localize new development changes. If you manually add Uid properties to a UI, the task is typically tedious and less accurate.



  • 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 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)]).

 


About Us



We are the Windows Presentation Foundation SDK writers and editors.

Comments (9)

  1. Pour ceux qui ne l’aurait pas remarqu&#233;, l’&#233;quipe en charge de SDK (Software Development Kit) de WPF (Windows…

  2. We (the US ISV Evangelism Team) hosted a successful ISV CTO Summit last month for 150 managed partners, achieving an 8 out of 9 event rating.  Our goals were to convey product info on emerging Microsoft technologies, provide strategy/roadmap insight via

  3. You can make the most of the globalization and localization functionality that is built into Windows…

  4. Many of my customers asked me: How WPF supports localization and globalization? Is there any built-in

  5. My team has been looking how to make localization support in WPF better.&#160; We hope to improve things

  6. Ol&aacute; a todos, Gostaria de aproveitar no primeiro post deste blog, para n&atilde;o s&oacute; desejar

  7. Several techniques exist for localizing WPF applications. I have yet to study them before making a choice

  8. jbe2277 says:

    We use an alternative approach with the old stable "ResX" files to localize a WPF application.

    This technique is better supported by Visual Studio 2008. Furthermore, you can use the same approach for WinForms as well.

    See also: Best Practices: How to localize a WPF application (with ResX files)

    http://compositeextensions.codeplex.com/Thread/View.aspx?ThreadId=52910

    jbe