I have a solution with a Windows Store app project and a Class Library project and I want to add Localization support.
How can I add the all the Resource files to my Class Library and use them in both my App and Class Library?
In order to avoid writing a lot of boilerplate and error prone code when you add a new resource string like:
- Add it to .resw file
- Add it to your Static class that provides access to the resource
- Add it to each language specific .resw file (ex: en, fr, pt, etc)
You can use the following approach:
- Create "Strings" folder and add there just one folder for default language (for example "en-US") in your Class Library
- Add Resources.resw file to "en-US" folder with required keys/values
- Install Multilingual App Toolkit
- Enable MAT in VS for your Class Library (VS->Tools->Enable Multilingual App Toolkit)
- Add required languages to your Class Library (VS->Project->Add Translation languages...)
- Install ResW File Code Generator VS extension
- Go to Resources.resw file properties and set Custom Tool to "ReswFileCodeGenerator" (you can also specify namespace in Custom Tool Namespace)
- To solve issue with supported languages detection(currently generated manifest contains supported languages according to folder structure "Strings/en-US") you need to add folders for all required languages in your App library ("fr-FR", "bg-BG", etc) and put Resources.resw file with only one fake key.
- Build your solution and enjoy!
With this approach all your resources are available via static class generated by ReswFileCodeGenerator and all of them work with x:uid in XAML. You don't need to care about keys synchronization between different languages. Also MAT can translate your resources for you.