【问题标题】:Localization UIAlertController (IOS)本地化 UIAlertController (IOS)
【发布时间】:2017-08-26 07:09:30
【问题描述】:

我有 ActionSheet 的代码,因为我可以翻译“复制”、“过去”、“发送”、“取消”等词。如何将它们翻译成其他语言?

我有一个文件 Localized.strings 可以这样使用吗?

actionSheetController.title = NSLocalizedString("Words", comment: "")

@IBAction func showActionSheetButtonAction(_ sender: Any) {
    let actionSheetController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)

    actionSheetController.addAction(
        UIAlertAction(title: "Copy", style: .default, handler: { [weak self] _ in
            guard let strongSelf = self else { return }

            UIPasteboard.general.string = strongSelf.displayResultLabel.text
            print ("Copy")

            let alert = UIAlertController(title: "Copied", message: "", preferredStyle: .alert)

            let when = DispatchTime.now() + 0.6
            DispatchQueue.main.asyncAfter(deadline: when){
                // your code with delay
                alert.dismiss(animated: true, completion: nil)
            }

            self?.present(alert, animated: true, completion:nil)
        })
    )

    actionSheetController.addAction(
        UIAlertAction(title: "Paste", style: .default, handler: { [weak self] _ in
            guard let strongSelf = self else { return }

            strongSelf.displayResultLabel.text = UIPasteboard.general.string
            print ("Past")

        })
    )

    actionSheetController.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))

    present(actionSheetController, animated: true, completion: nil)
}

【问题讨论】:

    标签: ios swift3 localization xcode8 uialertcontroller


    【解决方案1】:

    当您需要向用户显示本地化文本时,您应该只使用本地化字符串宏:

    let actionSheetController = UIAlertController(title: NSLocalizedString("Words", comment: "Title for Alert Sheet"), message: nil, preferredStyle: .actionSheet)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-20
      • 2017-11-22
      • 2014-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多