如何在IB [iPhone SDK]中使用NSLocalizedString? [英] How to use NSLocalizedString in IB [iPhone SDK]?

查看:82
本文介绍了如何在IB [iPhone SDK]中使用NSLocalizedString?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我以编程方式分配文本时,我可以使用NSLocalizedString(....),但是如果我直接在IB中写文本(比如UILabel)我该如何本地化呢?

When I assign text programmatically, I can use NSLocalizedString(....), but if I am writing the text directly in IB (say to a UILabel) how do I localize it?

推荐答案

一种解决方案是创建多个本地化的nib文件。如果您的本地化需求非常简单,并且您只是在开发结束时将资源转移到专业软件本地化程序,这可能效果最佳。

One solution is to create multiple localized nib files. This probably works best if your localization needs are very straightforward and you're simply going hand your resources over to expert software localizers at the end of development.

如果您是在开发过程中进行本地化并且UI正在快速变化,重复的nib文件可能会非常麻烦,因为每个UI tweek必须在每个本地版本的nib中重复。为避免这种情况,您需要在视图控制器中编写一些代码来处理设置本地化字符串,通常在视图控制器的 -viewDidLoad 方法中。确保每个具有本地化文本的控件都是 IBOutlet ,并将它们连接到IB中的视图控制器。然后你的视图控制器的 -viewDidLoad 将如下所示:

If you're localizing while you're developing and the UI is changing rapidly, duplicate nib files can be a big pain, since every UI tweek must be duplicated in each local version of the nib. To avoid this, you'll need to write some code in your view controllers to handle setting the localized strings, typically in the view controller's -viewDidLoad method. Make sure that every control with localized text is an IBOutlet and wired them up to your view controller in IB. Then your view controller's -viewDidLoad will look something like this:

- (void)viewDidLoad {
    [super viewDidLoad];
    hello.text = NSLocalizedString(@"Hello", @"Hello label");
    world.text = NSLocalizedString(@"world", @"world label");
    // ... etc
}

你做这种类型的观点在 -viewDidLoad 中设置,因为在 -init 中的对象才会完全创建$ c>方法运行。 -viewDidLoad -init 之后但在您的视图可见之前运行。

You do this type of view setup in -viewDidLoad since the objects in your nib aren't fully created until after your -init method runs. -viewDidLoad runs after -init but before your view becomes visible.

这篇关于如何在IB [iPhone SDK]中使用NSLocalizedString?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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