【发布时间】:2019-04-14 20:22:46
【问题描述】:
我今天一直在努力将我的应用程序翻译成不同的语言,但不知何故我遇到了一个奇怪的问题。没有错误,没有警告。
我已经翻译了整个应用程序(很多按钮、导航按钮、标签等)但是不知何故,这三个按钮没有被翻译,哈哈。
override func viewDidLoad()
{
super.viewDidLoad()
translateCode()
}
//Translating the language
func translateCode()
{
//This one works fine
header.title = NSLocalizedString("settingsHeader", comment: "")
history.text = NSLocalizedString("settingsHistory", comment: "")
dogpass.text = NSLocalizedString("settingsDogpass", comment: "")
settings.text = NSLocalizedString("settingsSettings", comment: "")
//This is not getting translated
profileBtn.setTitle(NSLocalizedString("profile1", comment: ""), for: .normal)
cpBtn.setTitle(NSLocalizedString("changePass1", comment: ""), for: .normal)
cdpBtn.setTitle(NSLocalizedString("change1", comment: ""), for: .normal)
//This one works fine
btn_logout.setTitle(NSLocalizedString("logout", comment: ""), for: .normal)
}
在本地化字符串中
//SettingsViewController
"settingsHeader" = "Inställningar";
"settingsHistory" = "Historik";
"settingsDogpass" = "Hundpass";
"settingsSettings" = "Inställningar";
"profile1" = "Min profil";
"changePass1" = "Ändra lösenord";
"change1" = "Ändra hund / person";
"logout" = "Logga ut";
故事板是用英文写的。 当我运行应用程序时,按钮文本仍然是用英文写的。
为了更清楚:
我尝试过的:
- 删除连接并重新添加。
- 更改了密钥的名称。
- 重新编写了按钮的代码。
所以一切都在翻译,但是这个!为什么?
【问题讨论】:
-
尝试删除派生数据。
-
缺少信息:
NSLocalizedString("profile1", comment: "")是否返回正确的值?如果没有,也许检查是否有隐形字符。甚至删除双引号,甚至手动编写密钥而不是复制/粘贴。你在其他地方设置profileBtn.setTitle()吗?还是profileBtn.title =? -
@Larme 我没有在其他任何地方设置它。我确实是手动写的。最后,就像我正在按的第 40 个按钮一样,其他所有按钮都可以正常工作。但不知何故,这不是,哈哈!我已经将它与其他人进行了比较,但看起来都一样。我很困惑。 :)
标签: ios swift localization