Multiple language support in Universal App

人走茶凉 提交于 2020-01-13 02:43:09

问题


This is not a question about standard localization - I know how to localize the app, use resources, Uid's and so on - this works perfectly.

The problem is that the app comes within a bundle, therefore when the user installs the app it covers only languages that are selected in device/phone settings. But I would like to provide an option in settings that would allow choosing a language regarding the settings. For this purpose, I can use ApplicationLanguages.PrimaryLanguageOverride, which works very nice when deployed via VS, but as I've mentioned - version from the store lacks resources, as not all are installed.

Does anybody know how to bypass this bundle behavior?

The problem is also that I'm using MAT (multilingual app toolkit) and my translation comes with xliff files. I've spent quite a lot of time to find a way to convert them to resw files, without success. Is there any way to do it (or I've to write my own converter)?


回答1:


You need to use ResourceContext:

var context = new ResourceContext(); // deliberately not using getForCurrentView()
context.Languages = new string() {"fr-fr"}; 
ResourceMap resourceMap = ResourceManager.Current.MainResourceMap.GetSubtree("Resources");
String str = resourceMap.GetValue("string1", context).ValueAsString;

More info at: 'How to load string resources' and 'ResourceContext class'ResourceContext class'.

PS. I have app in store and there is no problem with changing language without reinstall so all resources must be there




回答2:


Check out this: UWP: Resource file for languages is not deployed correctly you need to get rid of bundle in order for my code from above to work. Or you could check if chosen language is installed in OS and if not you could not allow user to choose it using:

Windows.System.UserProfile.GlobalizationPreferences.Languages


来源:https://stackoverflow.com/questions/30772472/multiple-language-support-in-universal-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!