如何使用Xcode 5本地化我的应用程序? [英] How to localize my app with Xcode 5?

查看:148
本文介绍了如何使用Xcode 5本地化我的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是关于如何使用Xcode 4本地化我的应用程序?问题。

如何使用Xcode 5.x本地化我的应用程序?

How do I localize my app with Xcode 5.x?

推荐答案

一旦你理解它就很简单。

It's quite simple once you understand it.

你要做的第一件事是为您的项目添加本地化文件。
为此,只需选择项目的主要组

The first thing you want to do is add a localization file to your project. To do so, simply select your project's main group

然后,从工具栏中选择文件→新建→文件... (或者只需按住⌘N

then, from the toolbar, select File → New → File... (or just hold down ⌘N) .

资源类别下,选择字符串文件
并将其命名为 Localizable.strings (请注意它区分大小写)。

Under the Resource category, select Strings File , and name it Localizable.strings (note that it is case sensitive) .

现在我们有了可本地化的文件,我们可以点击 Localize ... 按钮,在文件检查员

Now that we have our localizable file, we can click on the Localize... button, in the File Inspector

Xcode将询问您是否要本地化文件,只是cli ck on Localize with Base selected

Xcode is going to ask you if you want to localize the file, just click on Localize with Base selected .

现在下一部分有点棘手。我们需要输入我们项目的 Info 部分,为此,点击Xcode的 Navigator 中的项目文件,然后点击你的右边你会看到一个名为 PROJECT 的类别,点击这个类别下的项目文件

Now this next part is a bit tricky. We need to enter our project's Info section, to do so, click on the project file in Xcode's Navigator, then to your right you'll see a category named PROJECT, click on your project file under this category

现在我们可以添加我们想要的语言了本地化类别。我将添加挪威语

Now we can add our desired language under the Localizations category. I'll add Norwegian

重要我们只留下 Localizable.strings 在出现的菜单中检查文件$ ​​b $ b 。

It's important that we only leave our Localizable.strings file checked in the menu that appears .

现在我们可以在中扩展 Localizable.strings 文件导航器查看我们的可本地化文件

Now we can expand our Localizable.strings file in the Navigator to see our localizable files .

我们现在的 Base 文件(在我们的 Localizable.strings 中)文件),这将是我们的应用程序的主要语言,以及我们以前选择的语言。

We now how our Base file (within our Localizable.strings file), which will be our app's "main language", and our previously selected language.

知道这些文件的结构必须相同是很重要的。你会在一秒钟内看到我的意思。

It's important to know that the structure of these files needs to be identical. You'll see what I mean in just a sec.

在我们的 Base 中,我将添加一个字符串命名 it_worked ,并添加它的本地化

In our Base, I'll add a string named it_worked, and add it's localization

以我们之前选择的语言(在我的情况下挪威语),我将添加相同的字符串 it_worked (以保持结构),但具有不同的本地化

And in our previously selected language (In my case Norwegian), i'll add the same string it_worked (to keep the structure), but with a different localization

现在我们有了本地化文件,我们可以让我们的应用程序在需要时阅读它。

Now that we have our localized file, we can make our app read it when needed.

我在我的应用程序中添加了 UILabel ,所以我们可以让我们的应用程序显示本地化文本。

I added a UILabel to my app, so that we can make our app display the localized text.

[myLabel setText:NSLocalizedString(@"it_worked", nil)];

现在如果我启动我的应用程序,我们会看到我们的基本语言

Now if I launch my app, we'll see our base language

如果我将模拟器的语言更改为挪威语,我们会看到我们的其他语言

and if I change the language of the simulator to Norwegian, we'll see our other language

这篇关于如何使用Xcode 5本地化我的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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