除此之外,所有内容都已本地化翻译

时间:2019-04-09 17:27:57

标签: ios swift localization

今天我一直在努力将应用程序翻译成不同的语言,但是我却遇到了一个奇怪的问题。没有错误,没有警告。

我已经翻译了整个应用程序(很多按钮,导航按钮,标签等),但是不知何故,这三个按钮没有得到翻译,哈哈。

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";

故事板是用英语编写的。 而且,当我运行该应用程序时,按钮文本仍然是用英语编写的。

更清楚:

It is connected

我尝试过的事情:

  • 删除连接并重新添加。
  • 更改了密钥的名称。
  • 重新编写按钮的代码。

所以一切都在翻译中,但这!为什么?

1 个答案:

答案 0 :(得分:0)

我通过将标题从属性更改为普通来解决了这个问题。感谢您的帮助!

plain