Oksana
Oksana

Reputation: 13942

How can I localize text in xib views without creating xib for each language?

I want to localize text inside xib view. Currently I have several xibs for each language.

Is it possible to localize the text inside xib file without creating separate xibs for each language?

Upvotes: 11

Views: 5865

Answers (5)

Michael Dautermann
Michael Dautermann

Reputation: 89509

Sounds like you want to learn about .string files.

Here is a related question you can look at for more info: Open .string files as an NSDictionary

Upvotes: 1

Jidong Chen
Jidong Chen

Reputation: 450

I think localize xibs directly is not an good option. I'm using https://github.com/steipete/Aspects to hook the awakeFromNib method of UILabel and localize text there. Example:

 #define Localized(_v_) NSLocalizedString(_v_, nil)
 NSError *err = nil;
[UILabel aspect_hookSelector:@selector(awakeFromNib)
                 withOptions:AspectPositionAfter
                  usingBlock:^(id<AspectInfo> aspectInfo) {
                      UILabel *label = aspectInfo.instance;
                      NSString *lStr = Localized(label.text);
                      if (lStr) {
                          label.text = lStr;
                      }
} error:&err];

If you have UIButton and other UIView to handle, you could just hook awakeFromNib of UIView and localize each kind of view.

Upvotes: 0

WiseGuy
WiseGuy

Reputation: 429

This problem was driving me nuts.

I came across this post and several others while trying to make xib localization easier for myself. I posted my method of including IBOutles for labels/buttons on this question, worked great for me, keeps all changes limited to the Localization.strings files.

https://stackoverflow.com/a/15485572/1449834

Upvotes: 0

Vineesh TP
Vineesh TP

Reputation: 7963

Localization are applied for text not Xib. So, you don't need to consider xib file. Localization is easy not too Complicated. Check this link It will help You.

http://www.raywenderlich.com/2876/how-to-localize-an-iphone-app-tutorial

Upvotes: 0

Dheeraj Vepakomma
Dheeraj Vepakomma

Reputation: 28717

Coming from Android background, I was asking the same question. Even Apple recommends creating separate xib files for each language. Fortunately, this process can be automated using the ibtool in a build script. It's described nicely in this article.

Upvotes: 0

Related Questions