Localization 单机器人的定位
我的应用程序是使用标准的.NET RESX方法(即String.fr.RESX、Strings.de.RESX等)进行本地化的,在Windows Phone下非常有效 我正在使用MonoDroid移植到Android,当我在手机上切换区域设置时,我看不到本地化的UI。如果我将APK文件重命名为ZIP并打开它,我会看到它没有打包生成过程中生成的区域设置dll(即中间\.Resources.dll文件位于bin目录下,但没有打包到APK中) 我错过了什么?我曾尝试将RESX文件的构建操作从“嵌入式资源”更改为“安卓资源”,甚至更改为“安卓资产”,但没有成功 提前感谢您的帮助 干杯Localization 单机器人的定位,localization,xamarin.android,resx,Localization,Xamarin.android,Resx,我的应用程序是使用标准的.NET RESX方法(即String.fr.RESX、Strings.de.RESX等)进行本地化的,在Windows Phone下非常有效 我正在使用MonoDroid移植到Android,当我在手机上切换区域设置时,我看不到本地化的UI。如果我将APK文件重命名为ZIP并打开它,我会看到它没有打包生成过程中生成的区域设置dll(即中间\.Resources.dll文件位于bin目录下,但没有打包到APK中) 我错过了什么?我曾尝试将RESX文件的构建操作从“嵌入式资
沃伦我在monodroid irc频道上询问了这一点,官方回答是“还不支持,但我们确实有计划这样做” 您需要将resx文件转换为android xml格式(见下文),并将其添加到项目中,如下所示: 在我的应用程序(游戏)中,我需要按名称查找本地化字符串。实现这一点的代码很简单,但并不明显。我没有使用ResourceManager,而是将其替换为android:
class AndroidResourcesProxy : Arands.Core.IResourcesProxy
{
Context _context;
public AndroidResourcesProxy(Context context)
{
_context = context;
}
public string GetString(string key)
{
int resId = _context.Resources.GetIdentifier(key, "string", _context.PackageName);
return _context.Resources.GetString(resId);
}
}
因为我不是XSLT专家,所以我制作了一个命令行程序,用于将resx转换为Android字符串XML文件:
/// <summary>
/// Conerts localisation resx string files into the android xml format
/// </summary>
class Program
{
static void Main(string[] args)
{
string inFile = args[0];
XmlDocument inDoc = new XmlDocument();
using (XmlTextReader reader = new XmlTextReader(inFile))
{
inDoc.Load(reader);
}
string outFile = Path.Combine(Path.GetDirectoryName(inFile), Path.GetFileNameWithoutExtension(inFile)) + ".xml";
XmlDocument outDoc = new XmlDocument();
outDoc.AppendChild(outDoc.CreateXmlDeclaration("1.0", "utf-8", null));
XmlElement resElem = outDoc.CreateElement("resources");
outDoc.AppendChild(resElem);
XmlNodeList stringNodes = inDoc.SelectNodes("root/data");
foreach (XmlNode n in stringNodes)
{
string key = n.Attributes["name"].Value;
string val = n.SelectSingleNode("value").InnerText;
XmlElement stringElem = outDoc.CreateElement("string");
XmlAttribute nameAttrib = outDoc.CreateAttribute("name");
nameAttrib.Value = key;
stringElem.Attributes.Append(nameAttrib);
stringElem.InnerText = val;
resElem.AppendChild(stringElem);
}
XmlWriterSettings xws = new XmlWriterSettings();
xws.Encoding = Encoding.UTF8;
xws.Indent = true;
xws.NewLineChars = "\n";
using (StreamWriter sr = new StreamWriter(outFile))
{
using (XmlWriter writer = XmlWriter.Create(sr, xws))
{
outDoc.Save(writer);
}
}
}
}
//
///Conerts将本地化resx字符串文件转换为android xml格式
///
班级计划
{
静态void Main(字符串[]参数)
{
字符串infle=args[0];
XmlDocument inDoc=新的XmlDocument();
使用(XmlTextReader=新的XmlTextReader(内嵌))
{
inDoc.Load(读卡器);
}
字符串outFile=Path.Combine(Path.GetDirectoryName(infle),Path.GetFileNameWithoutExtension(infle))+“.xml”;
XmlDocument outDoc=新的XmlDocument();
outDoc.AppendChild(outDoc.CreateXmlDeclaration(“1.0”,“utf-8”,null));
XmlElement resElem=outDoc.CreateElement(“资源”);
outDoc.AppendChild(resElem);
XmlNodeList stringNodes=inDoc.SelectNodes(“根/数据”);
foreach(stringNodes中的XmlNode)
{
字符串键=n.属性[“名称”].值;
字符串val=n.SelectSingleNode(“值”).InnerText;
XmlElement stringElem=outDoc.CreateElement(“字符串”);
XmlAttribute nameAttrib=outDoc.CreateAttribute(“名称”);
nameAttrib.Value=key;
stringElem.Attributes.Append(nameAttrib);
stringElem.InnerText=val;
研究附加子对象(stringElem);
}
XmlWriterSettings xws=新的XmlWriterSettings();
xws.Encoding=Encoding.UTF8;
xws.Indent=true;
xws.NewLineChars=“\n”;
使用(StreamWriter sr=新StreamWriter(输出文件))
{
使用(XmlWriter=XmlWriter.Create(sr,xws))
{
outDoc.Save(writer);
}
}
}
}
Android中的本地化是通过文件夹标题实现的。请阅读本文以了解如何做到这一点