0
votes

I need to switch a UI language at runtime in a UWP app. And I want to show all languages which are localized, in the 'Strings' folder.

For example, I have added 'en-US', 'zh-CN', and 'ja-JP' resources in 'Strings' folder, so the app should support English, Chinese and Japanese.

But I want to get a list of how many languages have been added in the 'Strings' folder, programmatically. Thus, When I add a new language, I have no need to change the code.

1
One way could be accessing the Strings folder in the app using StorageFolder and using the GetFoldersAsync() call to get all the folders and check their name out using DisplayName property. Not sure if this is the best approach thoughAbsoluteSith
@AbsoluteSith, no, resource files are automatically complied into resources.pri file, there will be no such folders in installed location at all. Strings folder and those resource files can not be accessed using StorageFolder.Grace Feng
@GraceFeng-MSFT : Yes you're right my approach wouldn't work.AbsoluteSith

1 Answers

2
votes

You can get a list of all the language codes, your app is supporting by calling:

Windows.Globalization.ApplicationLanguages.ManifestLanguages

This method returns an IReadOnlyList<string> with all languages you have included into your project.