Today I want to share how I localized my Windows Store application, very easy! Localization can also be implemented using “Resources File (.resw)” files. I will try it soon but first I wanted to implement a solution using my already existing resx files.
To test the developing process for Windows Store and Windows Phone I am using this project structure:
All localization terms are already in a portable class library, so that they are share between the Windows Phone and Windows 8 applications.
The terms are contained in “resx” files:
- AppResources.resx (default app language, English)
- AppResources.es-ES.resx (Spanish)
- AppResources.fra.FR.resx (French)
These files contains a list of string properties that we can create be created easily using the editor:
Once the project is compiled a class “AppResources” with a property of type string with each entrance of the table is created. The value of the string is resolved using the resx corresponding to the current language of the UI Thread.
There are several ways to use this resources files in XAML, I wanted to use them with the support of IntelliSense, with my solution it is possible to define a common Localization Provider on my App.xaml that uses the resources files contained by the portable class library:
App.xaml, LocalizationProvider definition:
<Application x:Class="ChessClock.WindowsStore.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:utils="using:ChessClock.Core.Utils"> <Application.Resources> <ResourceDictionary> <!--Localization Provider--> <utils:Localization x:Key="LocalizationProvider"/> </ResourceDictionary> </Application.Resources> </Application>
The Localization Provider is a class that should be non static, so that it is possible to create a common instance in App.xaml. this class contains only one static property that returns a new instance of the AppResources class generated by the Resources files contained in the common project:
namespace ChessClock.Core.Utils { // Must not be static to use it in XAML public static class Localization { private static readonly AppResources resources = new AppResources(); /// <summary> /// Gets the application resources. /// </summary> public static AppResources Resources { get { return resources; } } } }
Example of Localized TextBox using the defined LocalizationProvider:
<TextBlock Text="{Binding Resources.NewGameMainPage, Source={StaticResource LocalizationProvider}}"/>
The last step to upload an application to the store supporting more than one language, this means not only an application that can run with different languages but also appears with a different description and screenshots on the store depending of the language, is to add this in the appxmanifest:
<Resources> <Resource Language="x-generate" /> <Resource Language="es-ES" /> </Resources>
Now the application is almost ready to be uploaded to the Windows Store!
–
My next step will be to create again the same application using Windows Universal Application.
References:
Pingback: My first Windows Store application is already published! | Juan Carlos Sánchez's Blog
Hi.
Did you succeed to handle localization in a Windows Universal Application, using an external project for handling localization and an helper Localization class in order to have, also using resw resource files, the capability to not duplicate common entries?
I am having problems: I can manage the localization only if the Resources.resw files are in the Shared project (in the proper String/xx-yy directory) using a class like this:
public class LocalizedStrings {
public string this[string key] {
get {
return ResourceLoader.GetForViewIndependentUse().GetString(key);
}
}
public static String GetString(String key) {
return ResourceLoader.GetForViewIndependentUse().GetString(key);
}
}
}
Unfortunately if the Resource.resw file is in the Shared project it is not possible to set in the property the Custom Tool as PublicResXFileCodeGenerator (to have the Resource.Designer.cs class generated). If I try, as I would prefer, to create a separate project (a portable one) to handle localization, because of the need to have each Resources.resw file in .separate directory related to a specific language, I am not able to make the things work!!
Any suggestion and/or code example is appreciated 🙂
Enzo Contini
LikeLike
Hello Enzo,
I am sorry but I did try out the localization of Universal Apps yet. I can only tell you something that probably you already know.
When you create a universal app a resw file is created in the project shared between the windows store and windows phone.

I don’t know if this solution is ok for your requirements but this is the recommended way to share localization in Universal Applications.
Please let me know if you find a better solution!
Thanks!
LikeLike
Hi Juan Carlos, I had a similar approach in my app but, at some point, it didn’t work no more.
In particular, I have an app based on mvvmcross 4.3, Xamarin.Android and Windows Phone 8.1.
I have a PCL project dedicated to the string resources: the same are for Android and Windows Phone 8.1.
Actually, I don’t know exactly after which update my localization solution stopped to work (maybe Visual Studio 2015 Update 4?), but until a month ago I can run it in the emulator (both debug or release) and by changing the system language I could see the effect in the app. Since the last month my app just ignore the regional settings and just work ONLY with default language (that one you set in manifest).
Thanks to your post I’ve found a solution: add a “Resource” item for each non-default language in the app manifest.
So, many thanks for your post… anyway I’m really curious about the reason of this problem.
I post this feedback here to ask if you (or someone else) know the solution.
Thanks
LikeLike