Resources (.resw) and ResourceLoader in .Net for Metro Style Apps

This post is part of a series of ‘Lessons Learnt’ from  a recent conversion of Microsoft.Practices.Prism to Net Metro Prism. See  here for related posts

In Metro there is a whole new improved mechanism for dealing with resources and localization. Its quite powerful; allowing one to embed text, images  and even Resource-Dictionaries that can vary from one locality to another.

If you’re used to Resource.resx files (for specific language/culture);  then you may be surprised to find its not an option with Metro Apps.  Instead the new file type is a Resource.resw that allows one to enter String Resources.

A quick web search of this new resource file gave me the wrong impression of how to do localization in Metro. Many forums commented on the lack of the usual auto generated code to access resources. Most suggested avoiding ResourceManager and using ResourceLoader. Others commented that embedding localized image resources in metro is not supported.

It true that the new preferred way of loading resources is using the ResourceLoader class

A number of code snippets show the following code:

ResourceLoader rl = new ResourceLoader("MyAssembly/Resources"); string localizedString = rl.GetString("MyLocalizedStringKey");  

This code will access any resources you add to “MyAssembly/Resources.resw”   

….but I was left a little confused. How do I know the path to specify for my Resource file?   How can I swap between different languages using this? I also wanted to know how to change images based on the current language of the user.

Fortunately I kept looking and came across this 3 part blog post, Part 1, Part 2and Part 3 – that do an excellent job of explaining it all.

Basically you organise you’re solution so that it contains folders for specific language codes. For example:

image

You add a resources.resw into each folder and put the appropriate language variants in each

You simply create an instance of ResourceLoader without passing a specific resource file into the ctor:

ResourceLoader rl = new ResourceLoader(); string localizedString = rl.GetString("MyLocalizedStringKey");

And voila, you app will magically have the correct language based on your windows language settings. (To understand the magic, read Part 2and Part 3)

You can access the current User’s language choice using Windows.System.UserProfile.GlobalizationPreferences.Languages. This returns the list of language choices (a user can have a order (or fallback) of preferred languages). The most preferred language is first in the list.

var languages = Windows.System.UserProfile.GlobalizationPreferences.Languages; string preferredLanguage = languages.ToList()[0];

Images (and other Assets) work in exactly the same manner. Just name a folder after the language code you’re catering for and add similar resources into it. See below

image

Note:

  • Do use an appropriate language code (en-GB, fr-FR)
  • Do use a consistent name for assets in each language folder (flag)
  • Do remember case sensitivity (it has to be consistent)

Now to use my localised flag.png file I simply use the following line of code:

myImageControl.Source = new BitmapImage(new Uri(@"ms-appx:/Assets/flag.png"));

Notice that I do not refer to a specific file in my application; simply the assets folder.

Also notice the use of ms-appx: – In metro you cannot use relative Uri to a resource – it must be absolute. ms-appx:  is equivalent of using [packagename]

So now I could vary my application based on the users preferred language. As the user changes between English (en-GB) and French (fr-FR) language, the application automatically updates the greeting and the  flag displayed:

image image

To automatically respond to a user changing language (cos that happens every day), there is an event that you can subscribe to.

var manager = Windows.ApplicationModel.Resources.Core.ResourceManager.Current; manager.DefaultContext.QualifierValues.MapChanged += QualifierValues_MapChanged;

 

If anyone wants the source code for this app; then let me know and I’ll make it available

129 Replies to “Resources (.resw) and ResourceLoader in .Net for Metro Style Apps”

  1. I just noticed that specifying the "MyAssembly/Resources" is not necessary. I have a /Resources/en-US/Strings.resw file and all that's required is the following: var res = new ResourceLoader("Strings"); Resources.Add("AppName", res.GetString("AppName")); I slapped that in my App:OnLaunched() method at the top and now my AppName is loaded properly.

  2. Oops! I see that I was reading your post wrong. I wish I could delete my comment now. Anyway, it's cool that the "MyLocalizedStringKey" shows up in Intellisense too. Thanks, Microsoft 🙂

  3. You really make it seem so easy with your presentation but I find this matter to be actually something that I think I would never understand. It seems too complex and very broad for me. I'm looking forward for your next post, I'll try to get the hang of it! Look into my web blog; szkola jezykowa wroclaw – http://altaling.eu/

  4. Volvo stands for reliability and durability. On our pages you will find a large number of used Volvo's in excellent condition. A Volvo possesses these properties as a new Volvo, but is considerably cheaper.

  5. hello there and thank you for your info – I have definitely picked up anything new from right here. I did however expertise some technical points using this site, as I experienced to reload the site lots of times previous to I could get it to load correctly. I had been wondering if your web hosting is OK? Not that I am complaining, but sluggish loading instances times will sometimes affect your placement in google and can damage your high quality score if ads and marketing with Adwords. Well I'm adding this RSS to my email and can look out for a lot more of your respective fascinating content. Make sure you update this again soon. Look into my web site :: Michael Kors Outlet – http://www.avlogbook.com/michael-kors-handbags.html

  6. I'm really inspired together with your writing talents as well as with the structure in your blog. Is this a paid subject matter or did you customize it yourself? Either way stay up the nice quality writing, it is rare to see a nice blog like this one today.. Feel free to visit my web site; Louis Vuitton Handbags Outlet – http://www.avlogbook.com/louis-vuitton-outlet.html

  7. It has natural components that make the viral throat infection alleviate faster. This may sound like an isolated case, but it's far from isolated. After the Elk Cloner infected Apple machine virus that infected IBM computers followed. My web blog: win32 blaster worm removal xp – http://ln-s.net/-QLz

  8. I think this is one of the most vital information for me. And i'm glad reading your article. But should remark on few general things, The web site style is ideal, the articles is really great : D. Good job, cheers Here is my website – online dominos vouchers ( Chasity – http://burnpit.us/users/hailworm10 )

  9. I'm not sure why but this web site is loading incredibly slow for me. Is anyone else having this problem or is it a problem on my end? I'll check back later and see if the problem still exists. Also visit my web site no deposit mobile casino bonus – Luke – http://karanmadhok.com/?p=34042

  10. Do you mind if I quote a couple of your articles as long as I provide credit and sources back to your website? My website is in the exact same niche as yours and my users would genuinely benefit from a lot of the information you provide here. Please let me know if this ok with you. Cheers! Feel free to surf to my webpage; dominoes Deals [ vdopak.org – http://vdopak.org/phpfox/upload/index.php?do=/blog/95/budget-busted-save-money-with-these-couponing-ideas/ ]

  11. Greetings! Quick question that's completely off topic. Do you know how to make your site mobile friendly? My weblog looks weird when viewing from my apple iphone. I'm trying to find a template or plugin that might be able to correct this issue. If you have any recommendations, please share. With thanks! Have a look at my web blog :: current dominos voucher codes – http://www.myfaceclick.com/blog/70264/simple-coupon-solutions-that-really-do-work-well/

  12. I don't know if it's just me or if everyone else experiencing problems with your blog. It appears as though some of the written text within your content are running off the screen. Can somebody else please comment and let me know if this is happening to them too? This might be a problem with my internet browser because I've had this happen previously. Appreciate it Feel free to surf to my website dominoes Voucher Codes – http://www.hummaa.com/user/hailnation54

  13. Just wish to say your article is as amazing. The clearness in your post is just excellent and i can assume you're an expert on this subject. Fine with your permission let me to grab your feed to keep up to date with forthcoming post. Thanks a million and please keep up the rewarding work. Here is my site; dominos online Vouchers – http://www.myfaceclick.comhttp://www.myfaceclick.com/blog/70264/simple-coupon-solutions-that-really-do-work-well/

  14. Simply want to say your article is as astounding. The clarity in your post is simply spectacular and i can assume you're an expert on this subject. Fine with your permission let me to grab your feed to keep up to date with forthcoming post. Thanks a million and please keep up the gratifying work. Take a look at my homepage – sytropin review – http://psycheluminous.com/activity/p/82/

  15. I usually do not drop a lot of comments, but i did some searching and wound up here Resources (.resw) and ResourceLoader in .Net for Metro Style Apps. And I do have 2 questions for you if you usually do not mind. Is it just me or does it look like a few of the remarks appear like they are left by brain dead people? 😛 And, if you are posting on other online sites, I would like to follow anything fresh you have to post. Would you list of every one of your social sites like your twitter feed, Facebook page or linkedin profile? Feel free to surf to my page van leasing – http://clkme.co/3es

  16. But a smiling visitor here to distribute the adore (:, btw outstanding layout. "Competition is a painful entity, but it produces great results." by Jerry Flint.

  17. The Zune concentrates on being a Portable Media Player. Not a web browser. Not a game machine. Maybe in the future it'll do even better in those areas, but for now it's a fantastic way to organize and listen to your music and videos, and is without peer in that regard. The iPod's strengths are its web browsing and apps. If those sound more compelling, perhaps it is your best choice.

  18. F*ckin? remarkable things here. I?m very happy to see your article. Thanks so much and i am looking ahead to contact you. Will you please drop me a mail?

  19. I have noticed that credit repair activity should be conducted with tactics. If not, you are going to find yourself damaging your position. In order to be successful in fixing your credit ranking you have to ensure that from this minute you pay your complete monthly dues promptly before their appointed date. It really is significant given that by not necessarily accomplishing so, all other activities that you will take to improve your credit standing will not be helpful. Thanks for revealing your strategies.

  20. It?s exhausting to search out educated individuals on this topic, but you sound like you realize what you?re talking about! Thanks

  21. I do not know whether it's just me or if perhaps everyone else experiencing issues with your blog. It appears as if some of the written text on your content are running off the screen. Can someone else please provide feedback and let me know if this is happening to them as well? This could be a problem with my browser because I've had this happen previously. Appreciate it My homepage; dieta ketogenica – http://vietnamlife.co.kr/xe/?document_srl=440153

  22. Does your blog have a contact page? I'm having trouble locating it but, I'd like to send you an e-mail. I've got some recommendations for your blog you might be interested in hearing. Either way, great blog and I look forward to seeing it grow over time. My blog post :: paleo breakfast recipes easy – http://blogs.rediff.com/paleorecipes/

  23. It's a shame you don't have a donate button! I'd definitely donate to this superb blog! I suppose for now i'll settle for bookmarking and adding your RSS feed to my Google account. I look forward to fresh updates and will talk about this blog with my Facebook group. Chat soon! Here is my page :: health insurance – http://www.newsannon.com/GYVDani

  24. The pharmaceutical companies would have you believe that a cure for Erectile Dysfunction – http://mwc-fr.info/wiki/Utilisateur:WaldoCrockett is recent with the discovery of Sidenafil (Viagra). There have been effective natural cures for Erectile Dysfunction for thousands of years. In more recent years with the introduction of modern extraction techniques used when manufacturing today's capsules and tablets the active ingredients are able to be taken up by the body more easily, making them even more effective.

  25. This is a good tip particularly to those fresh to the blogosphere. Brief but very precise information
 Thanks for sharing this one. A must read post! herpes symptoms in men mouth pictures – http://planetretcon.com/wiki/index.php5?title=User:AlineVanasqenu herpes symptoms in men mouth pictures – http://planetretcon.com/wiki/index.php5?title=User:AlineVanasqenu herpes symptoms in men mouth pictures – http://planetretcon.com/wiki/index.php5?title=User:AlineVanasqenu herpes symptoms in men mouth pictures – http://planetretcon.com/wiki/index.php5?title=User:AlineVanasqenu herpes symptoms in men mouth pictures – http://planetretcon.com/wiki/index.php5?title=User:AlineVanasqenu

  26. Today, while I was at work, my cousin stole my iphone and tested to see if it can survive a 40 foot drop, just so she can be a youtube sensation. My iPad is now destroyed and she has 83 views. I know this is totally off topic but I had to share it with someone! Review my blog post: Burn The Fat Feed The Muscle, http://ReviewBurnTheFatFeedTheMuscle.blogspot.com/http://ReviewBurnTheFatFeedTheMuscle.blogspot.com/ ,

  27. You really make it appear really easy along with your presentation but I in finding this matter to be really something which I think I would never understand. It seems too complicated and very large for me. I am looking forward to your next submit, I'll attempt to get the hold of it! Feel free to visit my homepage … Metabolic Cooking Review – http://metabolic-cooking–review.blogspot.com/

  28. Ich bin gerade zufaellig auf Ihrer Seite gelandet (war auf der Suche nach einer anderen Homepage). Ich moechte diese websiete nicht verlassen, ohne Ihnen ein Lob zu dieser klar strukturierten und schick designten Page zu hinterlassen! Louis Vuitton outlet store online – http://www.backdoorcollectibles.com Louis Vuitton Tennessee handbags – http://www.kurumaya21.com cheap Louis Vuitton – http://www.atholl1965.net Local outlet store – http://www.tredep24h.net Local outlet store – http://www.functionalenergybalancing.net

  29. A lot of diets are extremely reduced in healthy and balanced saturated fats and healthy proteins they will leave you feeling starved. The portion of The planet which principles in excess of 2008 can cause problems to Lizard individuals driving them to very rejecting and prideful. Just observe these Digital video disc and you can determine what they're declaring by examining the English language subtitles. 4. Take a walk in advance of an evening meal – http://www.goodwebdiscount.com/Ex-Recovery-Systemhttp://www.goodwebdiscount.com/Ex-Recovery-System

  30. Unquestionably believe that which you stated. Your favorite reason seemed to be on the web the easiest thing to be aware of. I say to you, I definitely get annoyed while people think about worries that they plainly do not know about. You managed to hit the nail upon the top as well as defined out the whole thing without having side-effects , people could take a signal. Will likely be back to get more. Thanks My site – homepage – http://parking-lotnisko-wroclaw.wizytowka.pl/

  31. Hey there! I've been following your web site for a long time now and finally got the courage to go ahead and give you a shout out from Dallas Texas! Just wanted to tell you keep up the fantastic work!

  32. Excellent weblog right here! Also your website so much up fast! What web host are you the usage of? Can I get your associate link on your host? I desire my website loaded up as fast as yours lol

  33. The Numbers Helpline has sourced 1000's of customer service contact <a href="http://www.numbershelpline.co.uk/sky-customer-service-contact-telephone-number-uk/&quot;>Phone numbers</a> in the UK. We know how hard it can be to find those <a href="http://www.numbershelpline.co.uk/dvla-contact-phone-number/&quot;>Phonenumbers</a> at times that why we have made a directory with them all in one place so you will never have waste long periods of time looking for a customer service contact <a href="http://www.numbershelpline.co.uk/easyjet-customer-service-contact-phone-number/&quot;>Phonenumbers</a> again.

  34. Hello.This post was extremely motivating, particularly since I was looking for thoughts on this subject last Tuesday.

  35. My coder is trying to persuade me to move to .net from PHP. I have always disliked the idea because of the expenses. But he's tryiong none the less. I've been using WordPress on a variety of websites for about a year and am anxious about switching to another platform. I have heard excellent things about blogengine.net. Is there a way I can import all my wordpress content into it? Any help would be really appreciated!

  36. Thanks For Making And Sharing This Really Educational Weblog Post Keep Up The Good Work!!! I Posted A Back Link To My Activate Windows Post To Share With You How To Activate Windows 7 Enjoy!

  37. annuaires-gratuit.com/ vous propose de créer gratuitement un annuaire de sites internet pour un bon référencement.

  38. annuaires-gratuit.com/ vous propose de créer gratuitement un annuaire de sites internet pour un bon référencement.

  39. annuaires-gratuit.com/ vous propose de créer gratuitement un annuaire de sites internet pour un bon référencement.

  40. annuaires-gratuit.com/ vous propose de créer gratuitement un annuaire de sites internet pour un bon référencement.

  41. annuaires-gratuit.com/ vous propose de créer gratuitement un annuaire de sites internet pour un bon référencement.

  42. Don’t fiddle with the price, just because business is low: Small businesses immediately seem to think that because the economy is in a recession and things are getting expensive, an obvious thing to do would be to reduce the prices and play the volume game. It won’t cut the cake, my friend. Your price must reflect the value that you give unto your customer and that is at least her perception. You are actually telling her that you might now render a far lower level of service than usual due to the fact that you lowered your prices. Instead, just reiterate your position and stick to your prices. Recession is for the economy, and cycles are for your business – no matter what your price levels are.

  43. This is definitely a blog that people need to get behind. The problem is, no one wants to do a great deal of reading and not have something else to stimulate the mind. This is the internet, after all. Maybe if you added a video or two to emphasize your point. Ill stick around, FOR SURE. But, I don't know if others will.

  44. Hyundai acquire made available those new series in the direction of Qualified Ceed level having a few highly easier modest Home theater merchandising. An ingenious in addition to perceptive <a href="http://www.nadirstar.com/libraries/&quot;>hogan uomo prezzo</a> approach have an effect on specific motives with including appealing basketball coupe fight regarding a American readers.

  45. Toyota use invented their specific most advanced version within the Pro Ceed series having a few seriously enticing quite short High definition tv promoting and marketing. An ingenious combined with easy-to-use <a href="http://www.nadirstar.com/libraries/&quot;>hogan shop online ufficiale</a> methods to hit their valuable objectives connected with that provide cost-efficient sports car hair-styling to a great Western european end user.

  46. Kia have got brought out their unique modern model to qualify for the Pro Ceed array including remarkably persuading small Television set promotion. A clever and also perceptive <a href="http://www.nadirstar.com/libraries/&quot;>hogan online</a> method to force their personal aims of the giving away cheap competitive sports vehicle designing towards a Eu individuals.

  47. Hey guys, newbie here. I've lurked around here for a little while and figured I'd join in! Looks like you've got quite a nice place here

  48. Normaal gesproken gooien we afval in een afvalcontainer. Deze kan je kopen, krijg je soms van de gemeente of je kan een <a href=”http://www.123afvalcontainer.nl”>afvalcontainers huur</a>

  49. Hey! This is my first visit to your blog! We are a group of volunteers and starting a new project in a community in the same niche. Your blog provided us useful information to work on. You have done a outstanding job!|

  50. You can certainly see your skills in the paintings you write. The arena hopes for even more passionate writers such as you who are not afraid to say how they believe. Always follow your heart. We may pass violets looking for roses. We may pass contentment looking for victory. by Bern Williams.

  51. Hi, I am regular user to this website and your contents are superb! I am Also running small blog about all one's need means Free images for commercial use and its called fifcu.com. If any of you desire free images for commercial reason come to me. 🙂 And cheers your awesome site!

  52. Keep up the abundant labor , I recite hardly any blog posts on this locate and I believe that your blog is rattling interesting and contains sets of fantastic information.

  53. you have nice blog can you allow me to share your post to mfb fanpage here > fb.com/viralberg or viralberg,, if you dont mind i can linkback to you

  54. Hello je imagine cela trÚs intéressant et je vais prolonger mes recherches dans ce sens. Merci pour ces précisions!

  55. I started creating templates, but I don't know how to make demos in my Joomla website, for my visitors to test them..

  56. Wow! Merely outstanding! Thank you so much for the info discussed! I know you have actually put a lot of effort right into this and I wished to tell you just how thankful I am! There need to be much more blog sites similar to this on the net! I will certainly subscribe and bookmark to your superior web site! Hope you produced a lot more awesome things in the near future and also I will certainly come back and read it! Keep up the great work!

  57. If you're localizing an app using .resw files, I recommend you have a look at the localization management platform https://poeditor.com – which is an online tool with a collaborative translation interface. You can localize software into as many languages as you need.

Leave a Reply

Your email address will not be published. Required fields are marked *