我在Xamarin有一个针对安卓、iOS和windows的项目。我使用core (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);
}"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");这对于Android和windows手机来说很好。
但对于iOS来说,这是行不通的。它总是从英文文件返回资源字符串。区域性设置正确,并以调试模式显示。但不知何故,它无法从荷兰资源加载资源字符串。
所以问题是,是否可以在所有平台上使用PCL来本地化字符串(.Net方式)?有人知道吗?提前谢谢。
发布于 2014-10-15 19:51:35
对于Xamarin项目的本地化,我使用了来自微软的多语言Android (详见)和T4模板,将输出从工具包转换为可用于安卓和iOS的格式。
这教程对这个过程有一个非常棒的概述,它基于这代码项目。
发布于 2015-01-19 11:30:23
以下任一项:
试试这个:
public string GetString()
{
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("nl-NL");
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("nl-NL");
// CommonResources is the name of my resource file
ResourceManager resManager = new ResourceManager(typeof(CommonResources));
return resManager.GetString("LoginLabel",CultureInfo.CurrentCulture);
}发布于 2015-03-12 07:07:59
你在真正的设备上测试过吗?在模拟器中,不可能改变文化。我的语言文件也有类似的问题。
https://stackoverflow.com/questions/23004414
复制相似问题