Using the Multilingual App Toolkit with WPF Applications

One of the toolkits available to app developers enabling them to reach new audiences is the Multilingual App Toolkit (MAT).  Using this toolkit, you can easily add multiple language support to Store apps on Windows 8.1 and Windows Phone 8.1 as well as WPF applications on Windows.  The toolkit can also use the Microsoft Translator Service to automatically translate the string resources in your app to other languages.

I would like to walk you through the process of using the MAT with WPF applications, where the process is slightly different than with Windows Store and Phone apps.

Prerequisites

  1. Install Microsoft Visual Studio 2013 Update 4
  2. Install Microsoft Multilingual App Toolkit

Start Using MAT with WPF Apps

  1. Open the WPF project in Visual Studio

  2. In the project settings, Application…Assembly Info, set the Neutral Language to your language; I selected English (United States)

  3. In the Tools menu, select Enable Multilingual App Toolkit.   When you do this, a Resources.qps-ploc.xlf file will be automatically added to the project Properties.  This will be used to create “Pseudo” translation.  Pseudo Language is an artificial modification of the software product intended to simulate real language localization. The pseudo language can be used to detect potential localizability issues or bugs early in the project cycle, before the actual localization starts.

  4. In the Solution Explorer, open the Properties…..Resources.resx and in the top bar of the editor, change the Access Modifier from Internal to Public

  5. During the build process, the MAT will automatically update the .xlf files, keeping them in sync. 

  6. When you add new strings to the Resources.resx file, build the project and then right click on .xlf files in the solution explorer and select Generate machine translations.

  7. For the strings in Xaml, you should use the x:Static extension to have the strings point to the .resx file:
    <Window x:Class="MultilingualApp.MainWindow"
    xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:properties="clr-namespace:MultilingualApp.Properties"
    Height="350" Width="525">
        <Grid>
            <StackPanel>
                <TextBlock
                     Text="{x:Static properties:Resources.TranslateMe}"/>
                <Button
                     Content="{x:Static properties:Resources.PressMe}"/>
            </StackPanel>
        </Grid>
    </Window>

  8. You should use the Resources.resx file for all of the localizable strings in your app.

  9. Add additional languages by right-clicking on the project, and selecting Add translation languages…

  10. You can use the Microsoft Translator Service to generate translations or send the .xlf files to translation services as it is in the localization industry standard XLIFF file format.

  11. In addition to language translations, the MAT also use the Microsoft Terminology APIs (Language Portal Provider).  This enables direct access to Microsoft’s product translation memories.  See this article for more details: https://blogs.msdn.com/b/matdev/archive/2014/07/01/new-version-of-microsoft-terminology-api-launched.aspx

Testing Pseudo Language

WPF uses the OS language by default so Thread.CurrentThread.CurrentUICulture and Thread.CurrentThread.CurrentCulture need to be manually set to ‘qps-PLOC’ since it is not a log-in language.  Here is how you can easily do that:

namespace MultilingualApp
{
    using System.Diagnostics;
    using System.Globalization;
    using System.Threading;
    using System.Windows;

/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
    private CultureInfo cultureOverride = new CultureInfo("qps-PLOC");

    public App()
    {
        if (Debugger.IsAttached == true && cultureOverride != null)
        {
           Thread.CurrentThread.CurrentUICulture = cultureOverride;
           Thread.CurrentThread.CurrentCulture = cultureOverride;
        }
    }
}

You can now see what the Xaml above translated to with the Pseudo translation:
image

Summary

The Multilingual App Toolkit along with the Microsoft Translator Service has made a difficult and often expensive process of globalizing and localizing apps easy and straightforward.  Now it is easy to localize WPF application as well as Windows Store and Windows Phone apps.

Thanks

Thanks to Cameron Lerum from the MAT team for helping with this article.