From 46e3f85903568eebccab982c846b9aee47b0146e Mon Sep 17 00:00:00 2001 From: True Zhuanjia Date: Thu, 25 Jul 2024 21:31:06 +0800 Subject: [PATCH] localize send command view --- Limelight/Localization/Localizable.xcstrings | 222 +++++++++++++++++- .../CommandManagerViewController.swift | 23 +- 2 files changed, 228 insertions(+), 17 deletions(-) diff --git a/Limelight/Localization/Localizable.xcstrings b/Limelight/Localization/Localizable.xcstrings index bff7ab12..ed191897 100644 --- a/Limelight/Localization/Localizable.xcstrings +++ b/Limelight/Localization/Localizable.xcstrings @@ -107,6 +107,18 @@ "state" : "translated", "value" : "新增" } + }, + "zh-Hant" : { + "stringUnit" : { + "state" : "translated", + "value" : "添加" + } + }, + "zh-HK" : { + "stringUnit" : { + "state" : "translated", + "value" : "添加" + } } } }, @@ -133,6 +145,29 @@ } } }, + "Alias" : { + "extractionState" : "manual", + "localizations" : { + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "别名" + } + }, + "zh-Hant" : { + "stringUnit" : { + "state" : "translated", + "value" : "别名" + } + }, + "zh-HK" : { + "stringUnit" : { + "state" : "translated", + "value" : "别名" + } + } + } + }, "Bitrate: %.1f Mbps" : { "extractionState" : "manual", "localizations" : { @@ -179,6 +214,29 @@ } } }, + "Command" : { + "extractionState" : "manual", + "localizations" : { + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "命令" + } + }, + "zh-Hant" : { + "stringUnit" : { + "state" : "translated", + "value" : "命令" + } + }, + "zh-HK" : { + "stringUnit" : { + "state" : "translated", + "value" : "命令" + } + } + } + }, "Connecting" : { "extractionState" : "manual", "localizations" : { @@ -438,6 +496,29 @@ } } }, + "Delete" : { + "extractionState" : "manual", + "localizations" : { + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "删除" + } + }, + "zh-Hant" : { + "stringUnit" : { + "state" : "translated", + "value" : "删除" + } + }, + "zh-HK" : { + "stringUnit" : { + "state" : "translated", + "value" : "删除" + } + } + } + }, "Delete Buttons Here" : { "extractionState" : "manual", "localizations" : { @@ -461,6 +542,29 @@ } } }, + "Done" : { + "extractionState" : "manual", + "localizations" : { + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "完成" + } + }, + "zh-Hant" : { + "stringUnit" : { + "state" : "translated", + "value" : "完成" + } + }, + "zh-HK" : { + "stringUnit" : { + "state" : "translated", + "value" : "完成" + } + } + } + }, "Drag and drop buttons onto this trash can to remove them from the interface" : { "extractionState" : "manual", "localizations" : { @@ -484,6 +588,52 @@ } } }, + "Edit" : { + "extractionState" : "manual", + "localizations" : { + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "编辑" + } + }, + "zh-Hant" : { + "stringUnit" : { + "state" : "translated", + "value" : "编辑" + } + }, + "zh-HK" : { + "stringUnit" : { + "state" : "translated", + "value" : "编辑" + } + } + } + }, + "Enter a new command and alias" : { + "extractionState" : "manual", + "localizations" : { + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "输入新命令和对应的别名" + } + }, + "zh-Hant" : { + "stringUnit" : { + "state" : "translated", + "value" : "输入新命令和对应的别名" + } + }, + "zh-HK" : { + "stringUnit" : { + "state" : "translated", + "value" : "输入新命令和对应的别名" + } + } + } + }, "Enter Custom Resolution" : { "extractionState" : "manual", "localizations" : { @@ -559,6 +709,29 @@ } } }, + "Exit" : { + "extractionState" : "manual", + "localizations" : { + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "退出" + } + }, + "zh-Hant" : { + "stringUnit" : { + "state" : "translated", + "value" : "退出" + } + }, + "zh-HK" : { + "stringUnit" : { + "state" : "translated", + "value" : "退出" + } + } + } + }, "Failed to quit app. If this app was started by another device, you'll need to quit from that device." : { "extractionState" : "manual", "localizations" : { @@ -743,9 +916,6 @@ } } }, - "Key" : { - "extractionState" : "manual" - }, "Launch App" : { "extractionState" : "manual", "localizations" : { @@ -1069,6 +1239,29 @@ } } }, + "New Command" : { + "extractionState" : "manual", + "localizations" : { + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "新建命令" + } + }, + "zh-Hant" : { + "stringUnit" : { + "state" : "translated", + "value" : "新建命令" + } + }, + "zh-HK" : { + "stringUnit" : { + "state" : "translated", + "value" : "新建命令" + } + } + } + }, "No video received from host." : { "extractionState" : "manual", "localizations" : { @@ -1742,6 +1935,29 @@ } } }, + "Send Commands" : { + "extractionState" : "manual", + "localizations" : { + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "发送命令" + } + }, + "zh-Hant" : { + "stringUnit" : { + "state" : "translated", + "value" : "发送命令" + } + }, + "zh-HK" : { + "stringUnit" : { + "state" : "translated", + "value" : "发送命令" + } + } + } + }, "Set PC/Game resolution:" : { "extractionState" : "manual", "localizations" : { diff --git a/Limelight/ViewControllers/CommandManagerViewController.swift b/Limelight/ViewControllers/CommandManagerViewController.swift index c105ca32..ea40fe06 100644 --- a/Limelight/ViewControllers/CommandManagerViewController.swift +++ b/Limelight/ViewControllers/CommandManagerViewController.swift @@ -173,9 +173,9 @@ import UIKit } @objc private func addButtonTapped() { - let alert = UIAlertController(title: "New Command", message: "Enter a new command and alias", preferredStyle: .alert) - alert.addTextField { $0.placeholder = "Command" } - alert.addTextField { $0.placeholder = "Alias" } + let alert = UIAlertController(title: SwiftLocalizationHelper.localizedString(forKey: "New Command"), message: SwiftLocalizationHelper.localizedString(forKey: "Enter a new command and alias"), preferredStyle: .alert) + alert.addTextField { $0.placeholder = SwiftLocalizationHelper.localizedString(forKey:"Command") } + alert.addTextField { $0.placeholder = SwiftLocalizationHelper.localizedString(forKey: "Alias") } alert.textFields?[0].keyboardType = .asciiCapable alert.textFields?[0].autocorrectionType = .no alert.textFields?[0].spellCheckingType = .no @@ -183,9 +183,7 @@ import UIKit alert.textFields?[1].autocorrectionType = .no alert.textFields?[1].spellCheckingType = .no - - - let submitAction = UIAlertAction(title: "Add", style: .default) { [unowned alert] _ in + let submitAction = UIAlertAction(title: SwiftLocalizationHelper.localizedString(forKey: "Add"), style: .default) { [unowned alert] _ in let keyboardCmdString = alert.textFields?[0].text ?? "" let alias = alert.textFields?[1].text ?? keyboardCmdString let newCommand = RemoteCommand(keyboardCmdString: keyboardCmdString, alias: alias) @@ -193,14 +191,14 @@ import UIKit //self.reloadTableView() // don't know why but this reload has to be called from the CommandManager, it doesn't work here. } - let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) + let cancelAction = UIAlertAction(title: SwiftLocalizationHelper.localizedString(forKey:"Cancel"), style: .cancel) alert.addAction(submitAction) alert.addAction(cancelAction) if let selectedIndexPath = self.tableView.indexPathForSelectedRow { let selectedCommand = CommandManager.shared.getAllCommands()[selectedIndexPath.row] alert.textFields?[0].text = selectedCommand.keyboardCmdString // load selected keyboard cmd string - //alert.textFields?[1].text = selectedCommand.alias + //alert.textFields?[1].text = selectedCommand.alias // leave the alias input field empty } self.present(alert, animated: true) @@ -251,8 +249,7 @@ import UIKit let selectedBackgroundView = UIView() selectedBackgroundView.backgroundColor = highlightColor // Color for the selected state cell.selectedBackgroundView = selectedBackgroundView - - + let command = CommandManager.shared.getAllCommands()[indexPath.row] cell.textLabel?.text = command.alias return cell @@ -275,7 +272,7 @@ import UIKit } if !isEditingMode { - // Call the dummy method for key-value sending implementation + // Sending keyboard command let command = CommandManager.shared.getAllCommands()[indexPath.row] sendKeyboardCommand(command) if !viewPinned { dismiss(animated: false, completion: nil) } // dimiss the view in sending mode & the view is not pinned @@ -283,9 +280,7 @@ import UIKit } private func sendKeyboardCommand(_ cmd: RemoteCommand) { - // Dummy implementation print("Sending key-value") - let keyboardCmdStrings = CommandManager.shared.extractKeyStrings(from: cmd.keyboardCmdString) sendKeyDownEventWithDelay(keyboardCmdStrings: keyboardCmdStrings!) } @@ -306,7 +301,7 @@ import UIKit } // 发送当前键的键盘按下事件 LiSendKeyboardEvent(keyCode,Int8(KEY_ACTION_DOWN), 0) - // 使用 asyncAfter 在指定延迟后发送下一个键的键盘按下事件 + // 使用 asyncAfter 在指定异步延迟后发送下一个键的键盘按下事件 DispatchQueue.main.asyncAfter(deadline: .now() + delay) { self.sendKeyDownEventWithDelay(keyboardCmdStrings: keyboardCmdStrings, delay: delay, index: index+1) // 跳过当前键,继续下一个 }