Xamarin UWP: Use multilanguage resource files properly
IIf you are experiencing the oddity that the UWP version of your application can’t find the correct language version of your ‘resx’ files, then you have probably fallen into the same error I did.
The language management of UWP apps works differently to its Android and iOS counterparts.
Reade more about it at: https://docs.microsoft.com/en-us/windows/apps/design/globalizing/manage-language-and-region
How the UWP deals with multilingualism in brief
Two different lists are considered as the list of languages supported by the application. One is the list of languages supported by windows (language pack installed), and the other is the list of languages supported by the application (resx files created for them). The intersection of these can only be handled by the language switching code.
Where to define all of the supported languages by the app
Easily, without mainting it you can define them in only one line making a change in ‘Package.appxmanifest
‘ file.
<Resources>
<Resource Language="x-generate" />
</Resources>
The x-generate value will collect all of the available languages on compile time.
Otherwise, you will need to list all of them one by one:
<Resources>
<Resource Language="EN-US" />
<Resource Language="JA-JP" />
<Resource Language="FR-FR" />
</Resources>
Best practice?
Perhaps, if the application is running on UWP platform, you should make an if statement for the runtime platform and filter out languages that are not supported by windows.
// Get all of the supported language by windows in BCP-47 language tag (i.e. "en-US")
IReadOnlyList<string> userLanguages = Windows.System.UserProfile.GlobalizationPreferences.Languages;
3 Comments
Leave a Reply Cancel reply
This site uses Akismet to reduce spam. Learn how your comment data is processed.
Hi, I am András,
I am a seasoned software engineer from Budapest, Hungary with a strong focus on mobile app development using .NET MAUI and Xamarin.Forms. My expertise also extends to website building for my happy customers and other complex system designing. I am passionate about developing well-organized, maintainable software solutions.
[…] Xamarin UWP: Use multilanguage resource files properly [#Xamarin #multilanguage #uwp #uwp issue #uwp multilanguage #xamarin #xamarin forms #xamarin.uwp] […]
[…] Xamarin UWP: Use multi-language resource files properly (András Tóth) […]
[…] Xamarin UWP: Use multi-language resource files properly (András Tóth) Your Christmas Holiday Gift from Telerik UI for .NET MAUI: Support for Preview 11, New TabView and Map Controls (Bianka Banova) Getting started with Font Scaling in .NET MAUI (Leomaris Reyes) […]