I have a UWP app that has a set of text files, one for every language that we support. I want to read the contents of one text file based on the language that the system is set to. For example lets say the text file is called MyTextFile.txt and the 2 languages I support are English and French, I would have the following 2 files in my package:
fr-fr\MyTextFile.txt
en-us\MyTextFile.txt
If the system is set to French, I want to load and read the French text file and display it's contents. My current solution is only working on my dev machine, when I deploy my app to a different machine it only works if the OS is English. If I set the OS to French and install my app, it does not load the text file. This is what I am doing:
1) I have my text files store under [appname]\Files[language]\MyTextFile.txt 2) I have a props file that loads the files, it contains this:
<PropertyGroup>
<FileDir>$(SolutionDir)App\[appname]\Files\</EulaDir>
</PropertyGroup>
<ItemGroup>
<Content Include="$(FileDir)\en-us\MyTextFile.txt">
<Link>en-us\MyTextFile.txt</Link>
</Content>
<Content Include="$(FileDir)\fr-fr\MyTextFile.txt">
<Link>fr-fr\MyTextFile.txt</Link>
</Content>
</ItemGroup>
</Project>
3) My code (which works in English) loads the file like this:
var rc = ResourceManager.Current.MainResourceMap.GetSubtree("Files").GetValue("MyTextFile.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 + "/" + "MyTextFile.txt"));
// Read the contents of the file
UI.Text = await FileIO.ReadTextAsync(file, UnicodeEncoding.Utf8);
Perhaps there is a better way for loading this text file in a different language? It has to be a text file because it contains some legal text and can't be a string in a resw file
thanks
George