我在 Xamarin Forms 应用程序、下面的 Localizer 类和三个资源文件(默认 en-us、es、ar)中对本地化资源使用 ResX 方法。
当 Android 设备设置为西类牙语时,会显示相应的翻译字符串,但当设备设置为阿拉伯语时,会显示默认字符串。我在应用程序 list 中设置了属性 android:supportsRtl:"true",并且我的目标是 Android 4.2 或更高版本。
我错过了什么?
public class Localizer
{
#region Constructors
public Localizer()
{
RefreshLocale();
this.Resources = new ResourceManager("MyApp.Resx.AppResources", typeof(Localizer).GetTypeInfo().Assembly);
}
#endregion Constructors
#region Methods
public void RefreshLocale()
{
this.Locale = DependencyService.Get<ILocale>().GetCurrent();
}
public string Localize(string key)
{
return this.Resources.GetString(key, new CultureInfo(this.Locale));
}
#endregion Methods
#region Properties
public string Locale { get; private set; }
private ResourceManager Resources;
#endregion Properties
}
最佳答案
哎呀,又被咬了。对于阿拉伯语资源文件 AppResources.ar.resx,Build Action 设置为 None。添加具有此文件类型的文件时,这似乎是 Xamarin Studio 的默认行为。将 Build Action 更改为 EmbeddedResource,重新构建和部署,一切都按预期进行。
关于android - 阿拉伯语字符串未显示在 Xamarin Forms 应用程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29855717/