我在 Xamarin 中有一个针对 Android、iOS 和 Windows Phone 的项目。我使用核心(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”是我的资源键,它的值是“Sign in”(英语)和“inloggen”(荷兰语)。
我在我的 PCL 项目中为英语和荷兰语创建了两个资源文件 CommonResources。
CommonResources.resx
CommonResources.nl-NL.resx
在android、iOS和windows phone中,我设置culture如下:
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("nl-NL");
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("nl-NL");
这适用于 Android 和 Windows Phone。
但对于 iOS 它不起作用。它总是从英文文件返回资源字符串。文化已正确设置并以 Debug模式显示。但不知何故,它无法从荷兰语资源中加载资源字符串。
所以问题是,是否可以使用 PCL 为所有平台本地化字符串(.Net 方式)? 有人知道吗? 提前致谢。
最佳答案
为了对我们的 Xamarin 项目进行本地化,我使用了 Microsoft 的多语言应用程序工具包 ( detailed here ) 和 T4 模板,将工具包的输出转换为适用于 Android 和 iOS 的格式。
关于c# - 使用 xamarin 的移动跨平台本地化和仅 iOS 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23004414/