Reputation: 4641
I use XCode 6.
Imagine the following scenario: Your app's base language is English and you decide to add a German localisation. You now have two versions of Interface.xib
. If you were to add UI elements to the base version, you could simply convert the German version to localisable strings and back and all changes would be ported (if strings were added, those would have to be manually edited of course)
But what if it's the German version of Interface.xib
you edited? How do you get the new UI elements into the English version? You can't simply use the same trick, at least I have found no way to convert back from localised strings, probably XCode has no idea it should use the remaining German XIB and fill in the English localised strings.
What do I do, except always make UI changes in the base version in the future?
Upvotes: 2
Views: 416
Reputation: 4407
You can use a strategy to keep your XIBs or Storyboards in single file and locate visual components them on demand, programmatically making.
I created a demo project and put on my github:
I believe that with a few steps you can assess whether the strategy is valid for what you need:
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:
Upvotes: 2
Reputation: 4651
You are correct in your conclusion. The way localization is designed in Xcode expects you to originate all UI changes in the base language.
Upvotes: 2