Tuesday, June 15, 2010

WP7 Multilanguage App Proof Of Concept

For quite a while I wanted to write this post but always the same problem NO TIME. There is nothing innovative, but it's something that you might need/use in your apps. As you know I am romanian, I live in Italy and I usually develop in english :). So we usually add multilingual support to our solutions. The way we did it in previous version of Windows Mobile(Phone) is using xml files. I've implemented this mechanism slightly changed for WP7. I've added xml language files as resources to the solution. Each xml file has a tag which gives us the culture.
language name="English" culture="en-US"
I use it to set CurrentCulture and CurrentCultureUI of the current thread (it's just a proof of concept that can be improved).
Inside the language tag we have all the classes (xaml pages) with the various controls and properties that need to be set :

class name="MainPage" Title="Main Page"
control name="textBlockPageTitle" Text="MY APPLICATION"
Obviously it's easier to look at the code than to explain it. I also use a singleton class to share the XDoc, loaded from the xaml language, between various pages of the project and also to "translate" the pages.



There are still some problems with the ApplicationBar as there is no way to get a reference to the MenuItem using the name (when you debug the property doesn't even exist). I think it's a problem/missing feauture of the CTP. The solution I've adopted is to add a control name that doesn't exist on the page "AppBarMenuItem" that has 2 attributes Index and Text. This way I use the index to set the text of the MenuItem

control name="AppBarMenuItem" Index="1" Text="First"

The sample attached to this post is a project with 2 pages. If you need more details or you think it's useful please let me know

MultilanguageApp.rar

NAMASTE

3 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. Hi,

    Is this still the best solution? or did you change it?

    ReplyDelete
  3. There is an updated version:
    http://sviluppomobile.blogspot.com/2010/10/wp7-multi-language-v2.html

    ReplyDelete