How can I set up localization within my app?
iOS 有自己的方式来处理本地化。对于每种语言,您需要在项目中创建一个名为的文件夹language.lproj
where language
是 ISO 639-1 或 ISO 639-2 语言代码。首选两个字符 ISO 639-1 代码(例如 en、de、fr、it、...)。您可以找到包含 ISO 639-1 和 ISO 639-2 代码的表格here http://www.loc.gov/standards/iso639-2/php/code_list.php.
在新创建的文件夹中,您需要创建一个名为Localizable.strings
在这里您可以添加要本地化的字符串:
"stringToLocalize" = "This is the translation";
并将本地化字符串分配给例如UILabel
:
UILabel label = new UILabel();
...
label.Text = NSBundle.MainBundle.LocalizedString("stringToLocalize", null);
您甚至可以创建一个扩展方法(归功于另一个实验室 http://forums.xamarin.com/profile/2337/anotherlab):
public static class LocalizationExtensions
{
public static string t(this string translate)
{
return NSBundle.MainBundle.LocalizedString(translate, "", "");
}
}
How do I get it to choose Icelandic as the language since iOS does not have it as an available language?
我认为没有办法在 iOS 中选择冰岛语作为语言。我们的一款应用程序使用德语、意大利语和法语本地化。因为我们不需要英语,所以我们创建了en.lproj
其中包含德语本地化的文件夹。这样,即使设备的语言设置为英语,也会显示德语文本。也许您也可以在您的应用程序中执行类似的操作。