使用 Localizable.String 在 Xcode 4 中进行本地化 [英] Localizing in Xcode 4 with Localizable.String

查看:15
本文介绍了使用 Localizable.String 在 Xcode 4 中进行本地化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚更新到 Xcode 4.

I just updated to Xcode 4.

通常在本地化应用程序时,我们会添加Localizable.String";文件到项目,然后导航到获取信息"菜单并单击使其本地化"按钮.

Normally when localizing apps we add "Localizable.String" file to the project, and then navigate to "Get Info" menu and click the "Make It Localized" button.

但是,在 Xcode 4 中,没有获取信息";菜单.

However, in Xcode 4, there is no "Get Info" menu.

当我尝试添加一种语言时,它只会影响InfoPlist.String".文件(只能本地化应用名称).

When I try to add a language it only effects the "InfoPlist.String" file (which can only localize the app's name).

如何在 Xcode 4 中为我的应用添加本地化?

How may I add localization to my app in Xcode 4?

推荐答案

懂了就简单了.

如果您想使用 Xcode 5.x 和 iOS 7 或 Xcode 6.x 和 iOS 8,查看如何本地化我的应用程序用 Xcode 5?" 代替.

If you want to accomplish this with Xcode 5.x and iOS 7 or Xcode 6.x and iOS 8, check out "How to localize my app with Xcode 5?" instead.

我喜欢 SNRlink,但他的回答有点短.

I liked SNR's link, but his answer was a bit short.

另外,我看到这个问题有点老了,我的答案可能与旧版本的 Xcode 不同.(我使用 Xcode v. 4.3.3)

Also, I see that this question is a bit old, and my answer may be different from older versions of Xcode. (I used Xcode v. 4.3.3)

然而,我已经更新了我的答案以使用 both Xcode 4.3.5 及以下 + 4.4及更高版本(以及 Xcode 5.x 和 6.x 此处:如何使用 Xcode 5 本地化我的应用程序?).

However, i have updated my answer to work with both Xcode 4.3.5 and below + 4.4 and above (and Xcode 5.x and 6.x here: How to localize my app with Xcode 5?).

首先,您应该在 iOS 资源类别中添加一个新的字符串文件".

To begin you should add a new "Strings File" in the iOS Resource category.

接下来,将文件创建为Localizable.strings".

Next, create the file as "Localizable.strings".

创建文件后,选择它并打开文件检查器.

When the file is created, select it and open File Inspector .

编辑:随着新的 Xcode 4.4、4.5(及更高版本)(用于 iOS 6 支持),情况发生了一些变化.如果您使用 Xcode 4.4 或以上,请跳过此步骤.

EDIT: Things have changed (a bit) with the new Xcode 4.4, 4.5 (and above) (for iOS 6 support). If you'r Not using Xcode 4.4 or above, joust skip this step.

{ Xcode 4.4、4.5(及以上)方式:

点击本地化"按钮

现在转到您的主项目页面.

Now head over to your Main Project page.

然后单击本地化下的+"按钮,然后选择您要支持的语言.

And click the "+" button under Localization, and select the languages you want to support.

(我会选择德语/德语)

(I'll select German / Deutsch)

现在将出现一个窗口,询问您要本地化哪些文件,确保选择Localizable.strings"文件,然后单击完成".

Now a window will appear asking you what files you want to localize, make sure Only the "Localizable.strings" file is selected and click Finish.

}

{ Xcode 4.3.5 及以下方式:

{ The Xcode 4.3.5 and below way:

单击本地化"下的+"按钮,然后选择您要支持的语言.

Click the "+" button under Localization, and select the languages you want to support.

(我会选择德语/德语)

(I'll select German / Deutsch)

}

.

.

.

.

您现在应该看到Localizable.strings"文件下有两个文件.

You should now see that you have two files under the "Localizable.strings" file.

接下来,在两个本地化文件中添加本地化字符串.

Next, add your localization strings inside both of the localization files.

现在是编码部分.

在这里,我将简单地声明一个 UILabel 并将其文本设置为可本地化的文件字符串.

Here i'll simply declare a UILabel and set it's text to the Localizable file string.

声明:

IBOutlet UILabel *testLabel;

在 ViewDidLoad 中,我将使用 NSLocalizedString 设置文本:

And Inside ViewDidLoad i'll set the text using NSLocalizedString:

[testLabel setText:NSLocalizedString(@"TEST", nil)];

最后,只需在Interface Builder"中连接我们的 testLabel.

To finish up, just connect our testLabel in "Interface Builder".

现在您应该能够运行项目并查看本地化字符串.如果您更改语言,您应该也会看到本地化字符串的更改.

Now you should be able to run the Project and see the localized string. And if you change the language, you should see the localized string change as well.

这篇关于使用 Localizable.String 在 Xcode 4 中进行本地化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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