如何使用MonoTouch为iPhone应用程序使用多语言?

时间:2011-06-07 12:24:44

标签: iphone xamarin.ios monodevelop

如何在iPhone应用程序中使用多种语言?目前我只使用英语。但是将来我想要使用大约20到30种语言。如何在使用MonoTouch的iPhone开发中使用它?

1 个答案:

答案 0 :(得分:26)

您必须以“language.lproj”格式为您使用的每种语言创建一个文件夹(例如en.lproj,de.proj) - 在那里您必须创建一个名为Localizable.strings的文件(编译操作:含量)

文件看起来像这样:

"Name For Your String"="Translation For Your String";     // don't forget the semicolon!

然后你可以调用NSBundle.MainBundle.LocalizedString(“Name for YourString”,“”,“”)

这是一个简短的扩展方法,使翻译更容易:

public static class Extension
{
   public static string t(this string translate)
   {
      return NSBundle.MainBundle.LocalizedString(translate, "", "");
   }
}

你这样使用它:

// don't forget the using

"My String".t();
相关问题