【问题标题】:Do I have to hard-code / localise myself the "OK" button when generating an alert in swift?快速生成警报时,我是否必须对“确定”按钮进行硬编码/本地化?
【发布时间】:2016-02-03 03:47:45
【问题描述】:

我在 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 }
}

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

【问题讨论】:

    标签: ios swift localization


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-14
      • 2021-02-02
      • 1970-01-01
      • 1970-01-01
      • 2017-05-12
      相关资源
      最近更新 更多