skip to Main Content

My application have 3 language

For text in code, I can use Localizable.string file for set text for languages.

But for labels in storyboard I cant set Localizable.string value

How I can?

enter image description here

2

Answers


  1. Xcode supports localisation of storyboard, which is described in this iOS documentation

    This answer may also be helpful.

    There are various tools and methods to localise. I’d advise you to take some time to read about. As it’s an old and important subject, there’s a ton of information.

    Login or Signup to reply.
  2. You can create an extension of the UIKit component and localized text inside the awakeFromNib

    Here is demo

    extension String {
        var localized: String {
            return NSLocalizedString(self, tableName: nil, bundle: /** Your Bundle */, value: "", comment: "")
        }
    }
    

    For UILabel

    extension UILabel {
        open override func awakeFromNib() {
            super.awakeFromNib()
            if let textValue = self.text {
                self.text = textValue.localized
            }
        }
    }
    

    For UIButton

    extension UIButton {
        open override func awakeFromNib() {
            super.awakeFromNib()
            if let text = self.title(for: self.state) {
                self.setTitle(text.localized, for: self.state)
            }
        }
    }
    

    For UITextField

    extension UITextField {
        open override func awakeFromNib() {
            super.awakeFromNib()
            if let placeHolderValue = self.placeholder {
                self.placeholder = placeHolderValue.localized
            }
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search