Super-Easy Storyboard Localization

Daddycat @ Yinsee
Aug 28, 2017 · 1 min read

Eventhough we are now at iOS 11, Storyboard localization is still rather troublesome to work with.

Total pain in the arsss.

Here’s what I have come up with in SmartShopper’s iOS.

  1. Create a file called UILocalize.swift (or any name you prefer).

2. Extend the UI element you want to localized, add LocalisedXxxx attribute via IBInspectable

for example, to add localised title support to all UIButtons, we do

extension UIButton {
@IBInspectable var localizedTitle: String? {
get {
return nil // doesn't really matter
}
set {
if let newValue = newValue {
self.setTitle(NSLocalizedString(newValue, comment: ""), for: .normal)
}
}
}
}

3. Back in UI Builder, all buttons now have a new attribute named Localized Title

4. Now I just need to add this to my Localizable.string file, eg

“ADD_TO_FAVOURITES_CAPS” = “SIMPAN KE SENARAI KEGEMARAN”;

5. Now when you run your app in a language other than English, you should get the translated text!

)
Daddycat @ Yinsee

Written by

CTO / SmartShopper.my / 3b.my

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade