viernes, 25 de abril de 2014

Interfaz builder localization

Interfaz builder localization


Localizing your app is really important.

There are two main technics:

1. Localizing your xib. Then you end with a lot of repeated files.
2. Localizing your file in the viewDidLoad method, better but you have to define your uilabel only to localized it.

Or you can take advanced of the User Defined Runtime Attributes, on the Interface Builder.

First define a new category for UILabel:


#import "UILabel+Localized.h"

@implementation UILabel (Localized)

-(void) setTextLocalized:(NSString *)aText{
     [self setText:NSLocalizedString(aText, nil)];
}


@end


Of course you need to define your localized.strings and fill all the string you want to localize.

And finally in the interfaz builder:



And that's all.

This is only valid with static texts.

Good article with dynamics texts : http://www.objc.io/issue-9/string-localization.html

This can be done also with UIButton, UITextField.