Localizable.strings 不翻译短语
Localizable.strings not translating phrase
由于某些奇怪的原因,Localizable.strings 中只有部分文本翻译正确。如果字符串包含更多的 1 个单词(英文),它将不会被翻译。我确保它是相同的字符串(复制并粘贴)
"Login" = "כניסה"; //translates properly
"Email" = "דואר אלקטרוני"; //translates properly
"Password" = "סיסמא"; //translates properly
"forgot password?" = "שכחת סיסמא?"; //translation does not work
"Sign up" = "הירשם"; //translation does not work
我使用这个扩展:
extension String {
var localized: String {
return NSLocalizedString(self, tableName: nil, bundle: Bundle.main, value: "", comment: "")
}
}
在代码中:
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)
}
根据带有下划线的注册外观,您似乎有一个 NSAttributedString
,然后您在后续评论中确认了这一点。
虽然此处“忘记密码?”的代码部分不包括您在 viewDidLoad
其他地方使用的 localize
调用,但事实证明您还将其标识为属性字符串。
self.forgetPasswordButton.setTitle("forgot password?", for: .normal)
正如您在评论中指出的那样,已通过将本地化应用于属性字符串来更正此问题:
let attributeString = NSMutableAttributedString(string: "Sign up".localized,
attributes: yourAttributes)
self.signupButton.setAttributedTitle(attributeString, for: .normal)
由于某些奇怪的原因,Localizable.strings 中只有部分文本翻译正确。如果字符串包含更多的 1 个单词(英文),它将不会被翻译。我确保它是相同的字符串(复制并粘贴)
"Login" = "כניסה"; //translates properly
"Email" = "דואר אלקטרוני"; //translates properly
"Password" = "סיסמא"; //translates properly
"forgot password?" = "שכחת סיסמא?"; //translation does not work
"Sign up" = "הירשם"; //translation does not work
我使用这个扩展:
extension String {
var localized: String {
return NSLocalizedString(self, tableName: nil, bundle: Bundle.main, value: "", comment: "")
}
}
在代码中:
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)
}
根据带有下划线的注册外观,您似乎有一个 NSAttributedString
,然后您在后续评论中确认了这一点。
虽然此处“忘记密码?”的代码部分不包括您在 viewDidLoad
其他地方使用的 localize
调用,但事实证明您还将其标识为属性字符串。
self.forgetPasswordButton.setTitle("forgot password?", for: .normal)
正如您在评论中指出的那样,已通过将本地化应用于属性字符串来更正此问题:
let attributeString = NSMutableAttributedString(string: "Sign up".localized,
attributes: yourAttributes)
self.signupButton.setAttributedTitle(attributeString, for: .normal)