gpt4 book ai didi

ios - Localizable.strings 不翻译短语

转载 作者:行者123 更新时间:2023-11-28 05:54:57 27 4
gpt4 key购买 nike

由于某些奇怪的原因,只有 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)
}

enter image description here

最佳答案

根据带有下划线的 Sign up 的外观,您似乎有一个 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)

关于ios - Localizable.strings 不翻译短语,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51714419/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com