Localized your view within your xib

Application specific localization can be a nightmare.

Posted by Yeung Yiu Hung on February 21, 2016

As I start working on next phase of my project, I notice something common with my ViewControllers, a list of IBOutlet that only use once. They only use once for setting up static strings. Because this app has application specific localization (select language within the app, not using system’s one), localizing the xib is not an option. So my view controller have a lot of outlet that only use once.

One day, I read this article on NSHipster, and I think, what if I can set all the keys in my xib with IBInspectable, and using Objective-C Category to set up my string without create a list of IBOutlet that only call once?

So I created LocalizedView, a list of uiview categories that aims to set up static localized string within the xib, the app specific localization is done by AMLocalizedString, which is used in multiple projects that I have worked on.

The logic of this library is simple: I created a UIView category which contains an IBInspectable propery of localized key and a UIViewController category which loop through subviews and set the static string. You can see how simple to set the string from the follow video.