ios - 在快速生成警报时,我是否必须对 "OK"按钮进行硬编码/本地化?

标签 ios swift localization

我在 Swift (iOS 8+) 中有一个方便的方法来显示错误消息。到目前为止它看起来像这样:

// Supplied with a category code and an error code, generates an error dialogue box.
// Codes rather than strings because this needs to be localisable.
func showErrorDialogue(categoryCode: String, _ errorCode: String) -> () {
    // Fetch the actual strings from the localisation database.
    let localisedCategory = NSLocalizedString(categoryCode, comment: categoryCode)
    let localisedError    = NSLocalizedString(errorCode,    comment: errorCode)

    // Create an alert box
    let alertController = UIAlertController(
        title:          localisedCategory,
        message:        localisedError,
        preferredStyle: .Alert
    )
    alertController.addAction(
        UIAlertAction(
            title:   "OK", // FIXME: why isn't this localised?
            style:   .Default,
            handler: { (action) in return }
        )
    )
    self.presentViewController(alertController, animated: true) { return }
}

我不能只说“我只向这个警告框添加一个按钮,所以请假定它是区域设置默认的 OK 按钮”,这似乎很奇怪。到目前为止,我在有限的谷歌搜索中找到的最佳解决方案似乎是 Steal them from the System and hope这不仅仅是有点狡猾。

最佳答案

据我所知,没有比像您发现的那样从系统中窃取它更好的方法了。

虽然本地化并不是最难的事情,但我同意如果 Apple 在未来版本的操作系统中实现自动化,那就太好了。

关于ios - 在快速生成警报时,我是否必须对 "OK"按钮进行硬编码/本地化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35168135/

相关文章:

ios - CGRectOffset 后 AutoLayout 不工作

swift - URLSession dataTask 如何破译 NSURLError?

ios - 一次性将所有 Realm 对象转换为字典

ios - 如何动画进度 View ?

en_GB 的 Android Nougat 本地化问题

ios - AFIncrementalStore 的神奇记录

iphone - 生成调度源计时器事件时发生内存泄漏

ios - iOS 9 中的 HTTPS 请求 : NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)

macos - 本地化后 : Unable to find nib named . .. 在包路径中:(空)

ios - 在 iOS 中以编程方式更改应用程序中的语言