c# - 使用 xamarin 的移动跨平台本地化和仅 iOS 问题

标签 c# localization xamarin.ios xamarin.android portable-class-library

我在 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 的格式。

This教程对这个过程有一个很好的概述,它基于 this代码项目。

关于c# - 使用 xamarin 的移动跨平台本地化和仅 iOS 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23004414/

相关文章:

python - Django 本地化日期解析

ios - Xamarin Forms 应用程序 - 错误 ITMS-90171 bundle 结构无效

objective-c - 保护文件时保存或将整个文件内容保存在内存中时 NSData 是否流式传输?

c# - C#中使用NCHAR获取特殊字符

c# - 无法使用 Firefox 调试某些 asp.net core2.2 网页。如何使用 Firefox 进行调试?

c# - c# Forms 应用程序中的 Google 地球 map

iphone - 保留日期格式以修复iPhone SDK

c# - 单击按钮上的 Xamarin.Forms 动画(Flash 背景)

properties - 在 Struts 2 中放置属性文件的位置?

c# - 获取对 UINavigationController 的引用