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

查看:106
本文介绍了使用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?

推荐答案

一旦您理解它就很简单.

It's simple once you understand it.

如果要使用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.

我喜欢 SNR

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)

但是,我已经更新了我的答案,可以同时使用两者 Xcode 4.3.5 及更低版本+ 4.4 以及更高版本(以及Xcode 5.x和6.x此处):

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".

创建文件后,选择它并打开File Inspector.

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(及更高版本)方式:

{ The Xcode 4.4, 4.5 (and above) way:

点击进行本地化"按钮

Click the "Make localized" button

现在转到主项目页面.

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并将其文本设置为Localizable文件字符串.

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".

现在,您应该能够运行Project并看到本地化的字符串. 而且,如果您更改语言,您也应该会看到本地化的字符串也发生了变化.

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天全站免登陆