当我以编程方式分配文本时,我可以使用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之后,中的对象才会完全创建$ 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?
发布评论