0

I have a UWP app that has a resource file for every language that we support. If I change the language on the target machine to French (fr-FR) I correctly see all of our French strings loaded in the app. This all works as expected.

However, in another place in our app, we load a particular file based on the "Language" property from the resource manager, like this:

var rc =   ResourceManager.Current.MainResourceMap.GetSubtree("Files").GetValue("File.txt", ResourceContext.GetForCurrentView());

var lang = rc.Qualifiers.FirstOrDefault(q => q.QualifierName == "Language").QualifierValue;

// Get the file
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///" + lang + "/File.txt"));

On disk I have a different copy of "File.txt" in each language:

en-US\File.txt
fr-FR\File.txt
etc.

However I can only ever get the en-US file to be read. How do I compile our app in French, so the above snippet of code returns “fr-FR” for the “Language” qualifier?

Sebastian Brosch
  • 42,106
  • 15
  • 72
  • 87
  • With ResourceManager.Current.MainResourceMap you are getting access to .resw files. Do you have any .resw file in your project? Please describe it. – Alexej Sommer Aug 25 '16 at 11:16
  • Yes the app has lots of .resw files, one for each language that we support. It also has a props file that does the copying of the text files above. The props file contains this: en-us\File.txt fr-fr\File.txt – user6115111 Aug 25 '16 at 17:19

1 Answers1

0

I think that you are trying to do something what is described in this article: [WinRT] How to get the language code actually used to resolve a resource
It should work also with UWP applications.

But for my taste Windows.Globalization.ApplicationLanguages.Languages is better. You can get language with something like:

var fr=Windows.Globalization.ApplicationLanguages.Languages[0];
Alexej Sommer
  • 2,677
  • 1
  • 14
  • 25