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?
You can create multiple versions of a .nib file for each locale. There are also tools to let you edit the strings in them easily. Apple has pretty good documentation on this.
This is a large and complex topic. A good starting place is Introduction to Internationalization Programming Topics and there is also Preparing Your Nib Files for Localization
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.
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
}
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.