Super-Easy Storyboard Localization
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.
- 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!
