- The Multilingual App Toolkit (MAT): The Visual Studio extension helps you to manage a simple localization process and even lets you pre-translate automatically with Bing translation Services. It´s built for Windows Phone and Windows Store Projects. Here you can read some more about how to get started.
- Portable Class Libraries (PCL): This feature Comes as a Project type for Visual Studio and lets you create assemblies that can be shared across .NET platforms. Therefore you can only use a common set of API calls. Here you can find some more about PCLs and the supported APIs
- A Windows Phone Project with just the resource files and Multilingual App Toolkit enabled (1). I use it to manage my localization.
- A Portable Class Library project that includes all the .resx files as a link (2). It has all the platform Independent code in it that uses the resources (e.g. Models and Dataaccess, Viewmodels, Helpers)
- Seperate Projects for Windows Phone 7 and Windows Phone 8 that just have the platform dependent code in it (3) (e.g. views, platform dependent helpers). Any other .Net project could use the code (e.g. WPF, Silverlight, Windows Store)
Here is what you have to do in detail to get it to work:
- Create a new project that you can use for localization MAT (1) :
- the project could be any project type that supports the Multilingual App Toolkit (e.g. Windows Phone 8).
- You need to enable Multilingual App Toolkit ("Tools" -> "enable Multilingual App Toolkit")
- Add your translation languages (rightclick on project -> "add translation languages...")
- Build the project, so that MAT populates the .resx files)
- Delete the generated designer file for you default language resources (e.g. "AppResources.resx"). Also remove the "custom tool"/"single file generator" in the file properties.
- Create a new PCL project (2).
- By default, a PCL project will have "en" set as the neutral language inside the AssemlyInfo.cs file. So go therre and delete this line: [assembly: NeutralResourcesLanguage("en")]
- Add the .resx files as linked files (rightclick on project -> "Add" -> "existing item" -> "Add as link")
- Add the supported cultures to you project:
- rightclick on project -> "Unload Project"
- rightclick on project -> "Edit"
- Add the SupportedCultures xml element inside the first PropertyGroup element. It contains a list of supported cultures for the assembly: <SupportedCultures>de;fr;it</SupportedCultures>
- Sadly I did not get the Pesudo Language "qps-ploc" to work from the PCL. I ould be glad to hear an explanation, why PCL does not Support the Pseudo Language?
- Create a new Windows Phone 8 project (3) and reference the PCL project. Do the same for a Windows Phone 7 or other .Net project
I created an example solution that follows this approach:
PCLplusMAT.zip (~500kb)
The example app shows how you bind to the PCL resources and how to call localized helper methods |
There are two ways of how to use the resources
Localized-Portable-Classes:
You can have portable helper classes with MAT-managed localization or even put your localized Viewmodels into the PCL. This is actually the main purpose and also what I do.This is how a localized portable helper class could look like:
Exposed Resource Dictionary:
Use the resource dictionary inside the PCL throughout your .Net applications and bind to localized strings in Xaml. You could also accomplish this by linking to another set of resource files, but if you want to keep everything in one place, and as everything is set up allread, this is an easy way to use your resources from several peoject types:The PCL could expose the following class:
Then in your Plattform specific Project declare an instance of ot as a resorce inside App.xaml:
And bind to your localized strings inside your page.xaml:
If you add a new string just add it to AppResources.resx. It will show up instantly inside the designer just you are used to. In order to translate a string, you have to rebuild the MAT project (1) and head open the multilingual editor.
Hope this helps some of you. I´m open to any suggenstions or better ways to accomplish MAT+PCL.