使用xamarin进行移动跨平台的本地化,仅iOS发行 [英] Localization for mobile cross platform using xamarin and issue with iOS only

查看:108
本文介绍了使用xamarin进行移动跨平台的本地化,仅iOS发行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Xamarin中有一个针对Android,iOS和Windows Phone的项目.我使用核心(PCL库)在不同平台之间共享通用代码.我在核心库中添加了Resource文件(.net资源).Resx,并读取了特定于文化的字符串,我在其中一个ViewModel的代码段中使用了以下代码段:

I have a project in Xamarin which targets Android, iOS and windows phone. I used core (PCL library) to share common code between different platform. I added Resource files (.net resource) .Resx in my core library and to read the culture specific string i used following code snippet in one of my 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".

"LoginLabel" is my resource key and its value is "Sign in" (in english) and "inloggen" in dutch.

我在PCL项目中为英语和荷兰语创建了两个资源文件CommonResources. CommonResources.resx
CommonResources.nl-NL.resx

I created two resource files CommonResources for English and dutch in my PCL project. CommonResources.resx
CommonResources.nl-NL.resx

在android,iOS和Windows Phone中,我将文化设置如下:

in android, iOS and windows phone, I set culture as follow:

Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("nl-NL");
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("nl-NL");

这在Android和Windows Phone上正常运行.

This works fine for Android and windows phone.

但是对于 iOS ,它不起作用.它总是从英文文件返回资源字符串.区域性已正确设置,并以调试模式显示.但由于某种原因,它无法从荷兰资源中加载资源字符串.

But for iOS it does not work. It always return resource string from English file. The culture is properly set and it display in debug mode. but somehow it is not able to load the resource string from the dutch resource.

所以问题是,是否可以使用PCL在所有平台上本地化字符串(.Net方式)? 有人有什么主意吗? 预先感谢.

So the question is, it is possible to localize string(.Net way) using PCL for all platform? anyone has any idea? Thanks in advance.

推荐答案

对于我们Xamarin项目的本地化,我使用了多语言应用程序工具包(

For localization on our Xamarin projects I've used the Multilingual App Toolkit (detailed here) from Microsoft and T4 templates to transform the output from the toolkit to useable formats for Android and iOS.

教程以 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆