gpt4 book ai didi

swift - 将语言设置为简体中文 (Zh-Hans) 在 IOS9 上不起作用

转载 作者:行者123 更新时间:2023-11-30 13:11:02 24 4
gpt4 key购买 nike

我正在尝试将语言环境设置为 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并获取 bundle

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

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

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

最佳答案

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

[这对我来说很奇怪,我以前从未遇到过这个Image

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

关于swift - 将语言设置为简体中文 (Zh-Hans) 在 IOS9 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38733731/

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