Demonstrates an approach to internationalization use with centralized files.
You can use a strategy to keep your XIBs or Storyboards in single file and locate visual components them on demand, programmatically making.
I believe that with a few steps you can assess whether the strategy is valid for what you need:
- Configure your project in the languages you want to support;
- Create a file to support Location;
- With the created file, add the target language, then Xcode will create a file for each language and you can put your keys and translation values.
- Create your visual component inherited from its target;
If you customize a visual component (such as UILabel), override the method can 'drawRect' and dynamically replace the key placed in the text field. So you can keep the common design for all screens without the worry of maintaining more than one layout for internationalization.
- (void)drawRect:(CGRect)rect {
NSString *text = NSLocalizedStringWithDefaultValue([self text], nil, [NSBundle mainBundle], [self text], @"");
if (self.attributedText && [[self text] length] > 0) {
NSDictionary *attributes = [(NSAttributedString *)self.attributedText attributesAtIndex:0
effectiveRange:NULL];
[self setText:text];
self.attributedText = [[NSAttributedString alloc] initWithString:self.text attributes:attributes];
}else{
[self setText:text];
}
[super drawRect:rect];
}
When you run your project now note that the UILabel component will dynamically set the key value as you set the property of their XIB or Storyboard.
General helps:
- http://www.raywenderlich.com/64401/internationalization-tutorial-for-ios-2014
- http://www.appcoda.com/ios-programming-tutorial-localization-apps/