我正在尝试将语言环境设置为zh-Hans,并将占位符更改为简体中文文本。

我正在使用以下示例:https://github.com/anishparajuli555/SMSLocalization

当我尝试设置为其他语言时..它有效..但不适用于简体中文。我希望有人可以就此提出建议。我是ios开发的新手。是国家代码问题还是语言代码。因为我运行项目没有错误提示。

先感谢您...

这是我的代码:

LanguageManager.swift

override init() {

    let english = Locale()
    english.initWithLanguageCode("en", countryCode: "gb", name: "United Kingdom")

    let finnish  = Locale()
    finnish.initWithLanguageCode("fi", countryCode: "fi", name: "Finland")

    let chinese = Locale()
    chinese .initWithLanguageCode("zh-hans", countryCode: "zh-Hans", name: "China")

    self.availableLocales = [english,finnish,chinese]
 }


在我的ViewController.Swift中,我添加了另一个@IBAction来将语言环境设置为zh-Hans并获取捆绑包

@IBAction func showAlertInChinese(sender: AnyObject){
    LanguageManager.sharedInstance.setLocale("zh-Hans")
    bundle = LanguageManager.sharedInstance.getCurrentBundle()
}


这是我的Main.strings(简体中文)

/* Class = "UILabel"; text = "Name"; ObjectID = "5Pu-4M-URI"; */
"5Pu-4M-URI.text" = "Name";

/* Class = "UIButton"; normalTitle = "Finnish"; ObjectID = "Ezp-NI-f7w"; */
"Ezp-NI-f7w.normalTitle" = "Finnish";

/* Class = "UIButton"; normalTitle = "English"; ObjectID = "HBX-eg-qyo"; */
"HBX-eg-qyo.normalTitle" = "English";

/* Class = "UITextField"; placeholder = "Password"; ObjectID = "LS8-g7-7Vf"; */
"LS8-g7-7Vf.placeholder" = "Password";

/* Class = "UIButton"; normalTitle = "Chinese"; ObjectID = "UZ0-ba-gcI"; */
"UZ0-ba-gcI.normalTitle" = "Chinese";

/* Class = "UIButton"; normalTitle = "Login"; ObjectID = "ZYz-eL-ISh"; */
"ZYz-eL-ISh.normalTitle" = "Login";

/* Class = "UITextField"; placeholder = "userName"; ObjectID = "tGt-sW-fB7"; */
"tGt-sW-fB7.placeholder" = "userName";

/* Class = "UILabel"; text = "Password"; ObjectID = "xCL-5A-88z"; */
"xCL-5A-88z.text" = "Password";


而在我的Localizable.strings中,我设置了简体中文文本值

KUserName = "用户名";
KPassword ="密码";
KName = "名称:";
KPwd = "密码:";
KLogin = "登录";

最佳答案

由于某些原因,zh-Hans和zh-Hant被视为zh

[对我来说看起来很奇怪,我在Image之前从未遇到过

因此,您只能在此项目中使用“ zh”,而不是zh-Hans / zh-Hant,如果使用“ zh”,则可以使其正常工作

10-05 19:25