gpt4 book ai didi

swift - 如何在 Swift 中本地化警报消息框

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

我的警报框消息代码是

let alertController = UIAlertController(title: "Hello!", message:
"Good Morning Everyone!", preferredStyle: UIAlertControllerStyle.Alert)
alertController.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default,handler: nil))

我想翻译文本
你好大家早上好!
如何在 swift 中实现这个?

最佳答案

您可以使用 NSLocalizedString 来实现此目的。

let title = NSLocalizedString("Hello!", comment: "alertController title")
let message = NSLocalizedString("Good Morning Everyone!", comment: "alertController message")

let alertController = UIAlertController(
title: title,
message: message,
preferredStyle: UIAlertControllerStyle.Alert
)
alertController.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default,handler: nil))

然后cd进入项目目录并使用genstrings实用程序生成Localizes.strings文件。然后将其添加到项目中,并选择它。
在文件检查器中,单击本地化...,然后选择您要使用的语言。
这将为特定语言创建 Localized.strings 文件。

或者您可以选择您的项目,然后转到编辑器->导出进行本地化...
这将创建一个 XLIFF 文件,您可以在其中进行翻译,
然后使用编辑器->导入本地化...

将其导入回来

关于swift - 如何在 Swift 中本地化警报消息框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37854511/

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