将语言设置为简体中文(Zh-Hans)不适用于IOS9

时间:2016-08-03 03:09:09

标签: swift localization ios9 chinese-locale setlocale

我正在尝试将语言环境设置为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 = "登录";

1 个答案:

答案 0 :(得分:0)

出于某种原因,zh-Hans和zh-Hant被视为zh

[我觉得很奇怪,我在Image

之前从未遇到过这种情况

所以你只能在这个项目中使用“zh”而不是zh-Hans / zh-Hant,如果我使用“zh”,我设法让它工作