如何在IB [iPhone SDK]中使用NSLocalizedString?

编程入门 行业动态 更新时间:2024-10-21 16:38:35
本文介绍了如何在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 方法运行。 -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?

本文发布于:2023-11-28 07:22:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641452.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   IB   iPhone   SDK   NSLocalizedString

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!