Xamarin.iOS 上的本地化 [英] Localization on Xamarin.iOS

查看:19
本文介绍了Xamarin.iOS 上的本地化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Xamarin.iOS 上进行本地化.我一般不熟悉本地化,但我们想要做的第一种语言是冰岛语.如果您查看 iOS 设备本身的设置,则无法选择冰岛语.所以这是一个由两部分组成的问题.

I'm trying to figure out localization on Xamarin.iOS. I am new to localization in general, but the first language we want to do is Icelandic. If you look on the settings for the iOS device itself Icelandic is not an option. So this is a two part question.

  1. 如何在我的应用中设置本地化?我是否只是以与其他 .net 应用程序相同的方式进行本地化..或者我需要做一些特定于 iOS/Xamarin 的事情.

  1. How can I set up localization within my app? Do I just localize in the same manner as other .net apps..or is there something specific to iOS/Xamarin that I need to do.

一旦我实现了这个,我如何让它选择冰岛语作为语言,因为 iOS 没有它作为可用的语言?

Once I implement this, how do I get it to choose Icelandic as the language since iOS does not have it as an available language?

关于这个主题的文档似乎很少.

Documentation seems to be sparse on this topic.

推荐答案

如何在我的应用中设置本地化?

iOS 有自己的方式来处理本地化.对于每种语言,您需要在项目中创建一个名为 language.lproj 的文件夹,其中 language 是 ISO 639-1 或 ISO 639-2 语言代码.首选两个字符的 ISO 639-1 代码(例如 en、de、fr、it、...).您可以在此处找到包含 ISO 639-1 和 ISO 639-2 代码的表格.

iOS has its own way to handle localizations. For each language you need to create a folder in your project named language.lproj where language is ISO 639-1 or ISO 639-2 language code. Two character ISO 639-1 codes are preferred (e.g. en, de, fr, it, ...). You can find a table with ISO 639-1 and ISO 639-2 codes here.

在您新创建的文件夹中,您需要创建一个名为 Localizable.strings 的文件,您可以在此处添加要本地化的字符串:

In your newly created folder you need to create a file named Localizable.strings and here you can add your strings which you want to localize:

"stringToLocalize" = "这是翻译";

并将本地化字符串分配给例如 UILabel:

And to assign a localized string for example to a UILabel:

UILabel label = new UILabel();
...
label.Text = NSBundle.MainBundle.LocalizedString("stringToLocalize", null);

您甚至可以创建扩展方法(归功于 anotherlab):

You can even create an extension method (credit to anotherlab):

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

我如何让它选择冰岛语作为语言,因为 iOS 没有它作为可用语言?

我认为没有办法在 iOS 中选择冰岛语作为语言.我们的一个应用程序使用德语、意大利语和法语本地化.由于我们不需要英语,因此我们创建了 en.lproj 文件夹,其中包含德语本地化.这样,即使设备的语言设置为英语,德语文本也会出现.也许你也可以在你的应用中做这样的事情.

I don't think there is a way to choose Icelandic as a language in iOS. One of our apps uses German, Italian and French localizations. Since we don't need English we created en.lproj folder with German localizations in it. This way even if the language of the device is set to English, German texts will appear. Maybe you can do something like this too in your app.

这篇关于Xamarin.iOS 上的本地化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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