Problem in Localization of Windows Phone App

The short story:

Adding localization to a Windows Phone App failed and the App only showed the default language, unimpressed by changing language in the device settings. The reason was a mismatch between resource file name (*.de.resx) and supported cultures registered in the project file (de-DE).

The long story:

Today, I decided to add localization to an existing Windows Phone App. Unfortunately, it’s an old project compatible with Windows Phone 7, so I couldn’t use the auto-generation feature of resource files which Visual Studio offers for Windows Phone 8 projects. Instead – after adding an additional culture to the project properties – I created two resource files “AppResources” (one for the default “neutral” language (English), one for the additional language (German), and filled them with all my string values used in the project. However, when deploying the App on the device, everything was displayed in the default language, changing the device settings and setting them to any other language had no effect. I even tried to force the App to use the newly added German resource file by setting its current language to German while startup:

public App()
{
	...
	Thread.CurrentThread.CurrentUICulture = new CultureInfo("de-DE");
}

Still no effect. To check if the LocalizedStrings provider class was guilty, i even reduced the project to one single call to AppResources – Ignoring everything I’ve ever learning about MVVM, I tried assigning a string resource to one of the TextBlock controls on the App’s main page, somewhat like this:

this.PageTitle.Text = AppResources.String1;

Not even this test was positive. Finally it turned out that the German resource file could not even be found and opened by the system since the supported culture registered in the project settings (de-DE) did not match the name of the resource file (AppResources.de.resx). I had to either change the first one to “de”, or the resource file name to “AppResources.de-DE.resx” – tried both, and in both cases everything worked as expected!

Lessons learned:

Always make sure to use the correct culture suffix when naming resource files! If you selected a whole language in the “Supported Cultures” list (e.g., “German”, “English”, “French”, …), the corresponsing resource file name must end with the 2-letter language code (“AppResources.de.resx”, “AppResources.en.resx”, “AppResources.fr.resx”, …) If you selected a regional culture code (e.g., “English (United States)” or “German (Germany)”), the resource file name must contain the full culture code (“AppResources.en-US.resx”, “AppResources.de-DE.resx”, …)!

If you are unsure about the correct resource file naming (or experience problems like the one described above), open your Visual Studio project file (*.pcsroj for C#, *.vbproj for VB projects) in notepad or some other text editor. Don’t worry, this is a rather simple XML file. You just need to locate the portion of code inside the tag <SupportedCultures> – usually, this should be a list of culture-codes delimited by semicolons (;). For each code in this list (either 2-character language code, or full 5-character culture code), a corresponding resource file must exist in addition to the default resource file!

Simple example:

<SupportedCultures>fr;de-AT;de-DE;de-CH</SupportedCultures>

In this case, we will need the following five resource files:

  • AppResources.resx (The default language, e.g. English)
  • AppResources.fr.resx
  • AppResources.de-AT.resx
  • AppResources.de-DE.resx
  • AppResources.de-CH.resx