2017-08-26 9 views
0

ActionSheetのコードは "Copy"、 "Past"、 "Send"、 "Cancel"のように翻訳できます。どうすれば他の言語に翻訳できますか?ローカライゼーションUIAlertController(IOS)

Localized.stringsファイルを使用している可能性がありますか?

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

enter image description here

@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) 
} 

答えて

2

ユーザーにローカライズされたテキストを表示する必要がある時はいつでもあなただけのローカライズされた文字列のマクロを使用する必要があります。

let actionSheetController = UIAlertController(title: NSLocalizedString("Words", comment: "Title for Alert Sheet"), message: nil, preferredStyle: .actionSheet) 
関連する問題