Xamarin android App-将设备语言更改为“ he-IL”不会设置UICulture

问题描述

我在Visual Studio 2019上有Xamarin表单(v5.0.0.1558pre3)android应用程序 我希望我的应用程序支持不同的语言,所以我做了以下事情:

  1. 我已经为认语言资源创建了AppResources.resx,并为希伯来语语言创建了一个Resx文件,如下所示:Applisources.he-IL.resx:

enter image description here

  1. 我已将设备上的语言设置为希伯来语。

  2. 然后我将所有字符串设置为使用资源:

    Text =“ {x:静态资源:AppResources.MonthlyUsage}”

启动应用程序时,它仍会加载认的AppResources.resx值。

enter image description here

其他语言(例如fr-FR)的设置也很好。

解决方法

我认为在Android上,您需要像这样检查当前设置的Android语言环境:

var locale = Java.Util.Locale.Default;

Xamarin论坛上有一个线程描述了类似的问题:https://forums.xamarin.com/discussion/74484/app-crashes-when-language-set-to-hebrew

似乎您还必须将_替换为-,并且似乎需要将iw_IL更改为he_IL

您将不得不在启动时检测到此情况并相应地调整CurrentUICulture。