1
votes

For some weird reason only part of the texts in the Localizable.strings translates properly. If the string contain more the 1 word (the english side), it won't be translated. I made sure it is the same string (copied and pasted)

"Login" = "כניסה"; //translates properly 
"Email" = "דואר אלקטרוני"; //translates properly 
"Password" = "סיסמא"; //translates properly 
"forgot password?" = "שכחת סיסמא?"; //translation does not work
"Sign up" = "הירשם"; //translation does not work

I use this extension:

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

and in the code:

override func viewDidLoad() {
    super.viewDidLoad()
    self.emailTextField.placeholder = "Email".localized
    self.passwordTextField.placeholder = "Password".localized
    self.loginButton.setTitle("Login".localized, for: .normal)
    self.signupButton.setTitle("Sign up".localized, for: .normal)
    self.forgetPasswordButton.setTitle("forgot password?", for: .normal)
}

enter image description here

1
Do you hook all as outlets and change their text with NSLocalizedString ?? , or use Main.strings IB file ??Sh_Khan
Test for potential character coding issues introduced by your space. You may want to re-type the words just in case there is an issue.CodeBender
@Sh_Khan I've updated the questionLuda
You do not localize "forgot password?" and it appears you underline Sign up, perhaps that is why?CodeBender
@CodeBender You were right. The "Sign up" and "forgot password" are attributes strings and need to be set like this let attributeString = NSMutableAttributedString(string: "Sign up".localized, attributes: yourAttributes) self.signupButton.setAttributedTitle(attributeString, for: .normal). Wanna add this as an answer?Luda

1 Answers

1
votes

Based on the appearance of Sign up having an underline, it looks like you have an NSAttributedString, which you then confirmed in your follow up comment.

While your code section here for "forgot password?" does not include the localize call you use elsewhere in your viewDidLoad, it turns out that you also identified this as an attributed string.

self.forgetPasswordButton.setTitle("forgot password?", for: .normal)

As you noted in your comment, this was corrected by applying the localization to the attributed string:

let attributeString = NSMutableAttributedString(string: "Sign up".localized, 
                                                attributes: yourAttributes) 
self.signupButton.setAttributedTitle(attributeString, for: .normal)