Sof*_*San 15 c# localization xamarin.ios xamarin.android portable-class-library
我在Xamarin有一个针对Android,iOS和Windows手机的项目.我用核心(PCL库)在不同平台之间共享公共代码.我在我的核心库中添加了资源文件(.net资源).Resx,并在我的一个ViewModel中读取了我在以下代码片段中使用的特定于文化的字符串:
public string GetString()
{
// CommonResources is the name of my resource file
ResourceManager resManager = new ResourceManager(typeof(CommonResources));
return resManager.GetString("LoginLabel",CultureInfo.CurrentCulture);
}
Run Code Online (Sandbox Code Playgroud)
"LoginLabel"是我的资源键,其值为"登录"(英文)和荷兰语中的"inloggen".
我在我的PCL项目中为英语和荷兰语创建了两个资源文件CommonResources.
CommonResources.resx
CommonResources.nl-NL.resx
在android,iOS和windows手机中,我将文化设置如下:
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("nl-NL");
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("nl-NL");
Run Code Online (Sandbox Code Playgroud)
这适用于Android和Windows手机.
但对iOS来说它不起作用.它总是从英文文件返回资源字符串.文化已正确设置,并以调试模式显示.但不知何故,它无法从荷兰资源加载资源字符串.
所以问题是,可以使用PCL为所有平台本地化字符串(.Net方式)吗?有谁有任何想法?提前致谢.
归档时间: |
|
查看次数: |
4850 次 |
最近记录: |