From d073b3582db7d9d14431106e323ae42a9178c53a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Mon, 6 Feb 2017 04:20:13 +0100 Subject: [PATCH] i18n: wrap self.tf in unicode() where 'format' function is used Qstring (returned by self.tr) does not have 'format' method. Fixes QubesOS/qubes-issues#2599 --- qubesmanager/backup.py | 13 ++--- qubesmanager/create_new_vm.py | 10 ++-- qubesmanager/main.py | 89 ++++++++++++++++++----------------- qubesmanager/restore.py | 2 +- qubesmanager/settings.py | 20 ++++---- 5 files changed, 68 insertions(+), 66 deletions(-) diff --git a/qubesmanager/backup.py b/qubesmanager/backup.py index ea8f9bc..5d149e8 100644 --- a/qubesmanager/backup.py +++ b/qubesmanager/backup.py @@ -225,10 +225,11 @@ class BackupVMsWindow(Ui_Backup, QWizard): self.blk_manager.check_if_serves_as_backend(vm) reply = QMessageBox.question(None, self.tr("VM Shutdown Confirmation"), - self.tr("Are you sure you want to power down the following VMs: " - "{0}?
" - "This will shutdown all the running applications " - "within them.").format(', '.join(names)), + unicode(self.tr( + "Are you sure you want to power down the following VMs: " + "{0}?
" + "This will shutdown all the running applications " + "within them.")).format(', '.join(names)), QMessageBox.Yes | QMessageBox.Cancel) self.app.processEvents() @@ -354,7 +355,7 @@ class BackupVMsWindow(Ui_Backup, QWizard): print "Exception:", ex QMessageBox.critical(None, self.tr("Error while preparing backup."), - self.tr("ERROR: {0}").format(ex)) + unicode(self.tr("ERROR: {0}")).format(ex)) self.textEdit.setReadOnly(True) self.textEdit.setFontFamily("Monospace") @@ -390,7 +391,7 @@ class BackupVMsWindow(Ui_Backup, QWizard): else: self.progress_status.setText(self.tr("Backup error.")) QMessageBox.warning(self, self.tr("Backup error!"), - self.tr("ERROR: {}").format( + unicode(self.tr("ERROR: {}")).format( self.thread_monitor.error_msg)) else: self.progress_bar.setValue(100) diff --git a/qubesmanager/create_new_vm.py b/qubesmanager/create_new_vm.py index 997d79c..4e10a52 100644 --- a/qubesmanager/create_new_vm.py +++ b/qubesmanager/create_new_vm.py @@ -189,8 +189,8 @@ class NewVmDlg (QDialog, Ui_NewVMDlg): if self.qvm_collection.get_vm_by_name(vmname) is not None: QMessageBox.warning(None, self.tr("Incorrect AppVM Name!"), - self.tr("A VM with the name {0} already exists in the " - "system!").format(vmname)) + unicode(self.tr("A VM with the name {0} already exists in the " + "system!")).format(vmname)) return label = self.label_list[self.vmlabel.currentIndex()] @@ -240,7 +240,7 @@ class NewVmDlg (QDialog, Ui_NewVMDlg): thread.start() progress = QProgressDialog( - self.tr("Creating new {0} {1}...").format(vmtype, vmname), "", 0, 0) + unicode(self.tr("Creating new {0} {1}...")).format(vmtype, vmname), "", 0, 0) progress.setCancelButton(None) progress.setModal(True) progress.show() @@ -253,11 +253,11 @@ class NewVmDlg (QDialog, Ui_NewVMDlg): if thread_monitor.success: self.trayIcon.showMessage( - "VM '{0}' has been created.".format(vmname), msecs=3000) + unicode(self.tr("VM '{0}' has been created.")).format(vmname), msecs=3000) else: QMessageBox.warning(None, self.tr("Error creating AppVM!"), - self.tr("ERROR: {0}").format(thread_monitor.error_msg)) + unicode(self.tr("ERROR: {0}")).format(thread_monitor.error_msg)) self.done(0) diff --git a/qubesmanager/main.py b/qubesmanager/main.py index bc1750d..50ad8a5 100755 --- a/qubesmanager/main.py +++ b/qubesmanager/main.py @@ -102,10 +102,10 @@ class QubesManagerFileWatcher(ProcessEvent): "it into an application."), msecs=3000) else: - trayIcon.showMessage(self.tr( + trayIcon.showMessage(unicode(self.tr( "Qubes Clipboard fetched from VM: '{0}'\n" "Press Ctrl-Shift-v to copy this clipboard into dest" - " VM's clipboard.").format( + " VM's clipboard.")).format( src_vmname), msecs=3000) src_info_file.close() @@ -282,11 +282,11 @@ class VmShutdownMonitor(QObject): timedelta(milliseconds=self.shutdown_time): reply = QMessageBox.question( None, self.tr("VM Shutdown"), - self.tr("The VM '{0}' hasn't shutdown within the last " - "{1} seconds, do you want to kill it?
").format( + unicode(self.tr("The VM '{0}' hasn't shutdown within the last " + "{1} seconds, do you want to kill it?
")).format( vm.name, self.shutdown_time / 1000), self.tr("Kill it!"), - self.tr("Wait another {0} seconds...").format( + unicode(self.tr("Wait another {0} seconds...")).format( self.shutdown_time / 1000)) if reply == 0: vm.force_shutdown() @@ -1041,9 +1041,9 @@ class VmManagerWindow(Ui_VmManagerWindow, QMainWindow): (requested_name, ok) = QInputDialog.getText( None, self.tr("VM Removal Confirmation"), - self.tr("Are you sure you want to remove the VM '{0}'?
" + unicode(self.tr("Are you sure you want to remove the VM '{0}'?
" "All data on this VM's private storage will be lost!

" - "Type the name of the VM ({1}) below to confirm:") + "Type the name of the VM ({1}) below to confirm:")) .format(vm.name, vm.name)) if not ok: @@ -1053,7 +1053,7 @@ class VmManagerWindow(Ui_VmManagerWindow, QMainWindow): elif requested_name != vm.name: # name did not match QMessageBox.warning(None, self.tr("VM removal confirmation failed"), - self.tr("Entered name did not match! Not removing {0}.").format(vm.name)) + unicode(self.tr("Entered name did not match! Not removing {0}.")).format(vm.name)) return else: @@ -1065,7 +1065,7 @@ class VmManagerWindow(Ui_VmManagerWindow, QMainWindow): thread.start() progress = QProgressDialog( - self.tr("Removing VM: {0}...").format(vm.name), "", 0, 0) + unicode(self.tr("Removing VM: {0}...")).format(vm.name), "", 0, 0) progress.setCancelButton(None) progress.setModal(True) progress.show() @@ -1078,10 +1078,10 @@ class VmManagerWindow(Ui_VmManagerWindow, QMainWindow): if thread_monitor.success: trayIcon.showMessage( - self.tr("VM '{0}' has been removed.").format(vm.name), msecs=3000) + unicode(self.tr("VM '{0}' has been removed.")).format(vm.name), msecs=3000) else: QMessageBox.warning(None, self.tr("Error removing VM!"), - self.tr("ERROR: {0}").format( + unicode(self.tr("ERROR: {0}")).format( thread_monitor.error_msg)) @staticmethod @@ -1122,7 +1122,7 @@ class VmManagerWindow(Ui_VmManagerWindow, QMainWindow): (clone_name, ok) = QInputDialog.getText( self, self.tr('Qubes clone VM'), - self.tr('Enter name for VM {} clone:').format(vm.name), + unicode(self.tr('Enter name for VM {} clone:')).format(vm.name), text=(name_format % name_number)) if not ok or clone_name == "": return @@ -1134,7 +1134,7 @@ class VmManagerWindow(Ui_VmManagerWindow, QMainWindow): thread.start() progress = QProgressDialog( - self.tr("Cloning VM {0} to {1}...").format(vm.name, + unicode(self.tr("Cloning VM {0} to {1}...")).format(vm.name, clone_name), "", 0, 0) progress.setCancelButton(None) @@ -1149,7 +1149,7 @@ class VmManagerWindow(Ui_VmManagerWindow, QMainWindow): if not thread_monitor.success: QMessageBox.warning(None, self.tr("Error while cloning VM"), - self.tr("Exception while cloning:
{0}").format( + unicode(self.tr("Exception while cloning:
{0}")).format( thread_monitor.error_msg)) @staticmethod @@ -1187,7 +1187,7 @@ class VmManagerWindow(Ui_VmManagerWindow, QMainWindow): vm.resume() except Exception as ex: QMessageBox.warning(None, self.tr("Error unpausing VM!"), - self.tr("ERROR: {0}").format(ex)) + unicode(self.tr("ERROR: {0}")).format(ex)) return @@ -1201,18 +1201,18 @@ class VmManagerWindow(Ui_VmManagerWindow, QMainWindow): thread.daemon = True thread.start() - trayIcon.showMessage(self.tr("Starting '{0}'...").format(vm.name), msecs=3000) + trayIcon.showMessage(unicode(self.tr("Starting '{0}'...")).format(vm.name), msecs=3000) while not thread_monitor.is_finished(): app.processEvents() time.sleep(0.1) if thread_monitor.success: - trayIcon.showMessage(self.tr("VM '{0}' has been started.").format(vm.name), + trayIcon.showMessage(unicode(self.tr("VM '{0}' has been started.")).format(vm.name), msecs=3000) else: trayIcon.showMessage( - self.tr("Error starting VM '{0}': {1}").format( + unicode(self.tr("Error starting VM '{0}': {1}")).format( vm.name, thread_monitor.error_msg), msecs=3000) self.set_error(vm.qid, @@ -1250,19 +1250,19 @@ class VmManagerWindow(Ui_VmManagerWindow, QMainWindow): thread.daemon = True thread.start() - trayIcon.showMessage(self.tr("Starting '{0}'...").format(vm.name), msecs=3000) + trayIcon.showMessage(unicode(self.tr("Starting '{0}'...")).format(vm.name), msecs=3000) while not thread_monitor.is_finished(): app.processEvents() time.sleep(0.1) if thread_monitor.success: - trayIcon.showMessage(self.tr("VM '{0}' has been started. Start Qubes " - "Tools installation from attached CD") + trayIcon.showMessage(unicode(self.tr("VM '{0}' has been started. Start Qubes " + "Tools installation from attached CD")) .format(vm.name), msecs=3000) else: trayIcon.showMessage( - self.tr("Error starting VM '{0}': {1}") + unicode(self.tr("Error starting VM '{0}': {1}")) .format(vm.name, thread_monitor.error_msg), msecs=3000) self.set_error(vm.qid, @@ -1291,7 +1291,7 @@ class VmManagerWindow(Ui_VmManagerWindow, QMainWindow): vm.pause() except Exception as ex: QMessageBox.warning(None, self.tr("Error pausing VM!"), - self.tr("ERROR: {0}").format(ex)) + unicode(self.tr("ERROR: {0}")).format(ex)) return @pyqtSlot(name='on_action_shutdownvm_triggered') @@ -1303,9 +1303,9 @@ class VmManagerWindow(Ui_VmManagerWindow, QMainWindow): reply = QMessageBox.question( None, self.tr("VM Shutdown Confirmation"), - self.tr("Are you sure you want to power down the VM '{0}'?
" + unicode(self.tr("Are you sure you want to power down the VM '{0}'?
" "This will shutdown all the running applications " - "within this VM.").format(vm.name), + "within this VM.")).format(vm.name), QMessageBox.Yes | QMessageBox.Cancel) app.processEvents() @@ -1319,10 +1319,10 @@ class VmManagerWindow(Ui_VmManagerWindow, QMainWindow): vm.shutdown() except Exception as ex: QMessageBox.warning(None, self.tr("Error shutting down VM!"), - self.tr("ERROR: {0}").format(ex)) + unicode(self.tr("ERROR: {0}")).format(ex)) return - trayIcon.showMessage(self.tr("VM '{0}' is shutting down...").format(vm.name), + trayIcon.showMessage(unicode(self.tr("VM '{0}' is shutting down...")).format(vm.name), msecs=3000) self.shutdown_monitor[vm.qid] = VmShutdownMonitor(vm, shutdown_time, @@ -1340,9 +1340,9 @@ class VmManagerWindow(Ui_VmManagerWindow, QMainWindow): reply = QMessageBox.question( None, self.tr("VM Restart Confirmation"), - self.tr("Are you sure you want to restart the VM '{0}'?
" + unicode(self.tr("Are you sure you want to restart the VM '{0}'?
" "This will shutdown all the running applications " - "within this VM.").format(vm.name), + "within this VM.")).format(vm.name), QMessageBox.Yes | QMessageBox.Cancel) app.processEvents() @@ -1357,9 +1357,9 @@ class VmManagerWindow(Ui_VmManagerWindow, QMainWindow): reply = QMessageBox.question( None, self.tr("VM Kill Confirmation"), - self.tr("Are you sure you want to kill the VM '{0}'?
" + unicode(self.tr("Are you sure you want to kill the VM '{0}'?
" "This will end (not shutdown!) all the running " - "applications within this VM.").format(vm.name), + "applications within this VM.")).format(vm.name), QMessageBox.Yes | QMessageBox.Cancel, QMessageBox.Cancel) @@ -1371,11 +1371,12 @@ class VmManagerWindow(Ui_VmManagerWindow, QMainWindow): except Exception as ex: QMessageBox.critical( None, self.tr("Error while killing VM!"), - self.tr("An exception ocurred while killing {0}.
" - "ERROR: {1}").format(vm.name, ex)) + unicode(self.tr("An exception ocurred while killing {0}.
" + "ERROR: {1}")).format(vm.name, ex)) return - trayIcon.showMessage("VM '{0}' killed!".format(vm.name), msecs=3000) + trayIcon.showMessage(unicode(self.tr("VM '{0}' killed!")) + .format(vm.name), msecs=3000) @pyqtSlot(name='on_action_settings_triggered') def action_settings_triggered(self): @@ -1433,12 +1434,12 @@ class VmManagerWindow(Ui_VmManagerWindow, QMainWindow): if not vm.is_running(): reply = QMessageBox.question( None, self.tr("VM Update Confirmation"), - self.tr("{0}
The VM has to be running to be updated.
" - "Do you want to start it?
").format(vm.name), + unicode(self.tr("{0}
The VM has to be running to be updated.
" + "Do you want to start it?
")).format(vm.name), QMessageBox.Yes | QMessageBox.Cancel) if reply != QMessageBox.Yes: return - trayIcon.showMessage(self.tr("Starting '{0}'...").format(vm.name), + trayIcon.showMessage(unicode(self.tr("Starting '{0}'...")).format(vm.name), msecs=3000) app.processEvents() @@ -1465,7 +1466,7 @@ class VmManagerWindow(Ui_VmManagerWindow, QMainWindow): if vm.qid != 0: if not thread_monitor.success: QMessageBox.warning(None, self.tr("Error VM update!"), - self.tr("ERROR: {0}").format( + unicode(self.tr("ERROR: {0}")).format( thread_monitor.error_msg)) @staticmethod @@ -1495,7 +1496,7 @@ class VmManagerWindow(Ui_VmManagerWindow, QMainWindow): (command_to_run, ok) = QInputDialog.getText( self, self.tr('Qubes command entry'), - self.tr('Run command in {}:').format(vm.name)) + unicode(self.tr('Run command in {}:')).format(vm.name)) if not ok or command_to_run == "": return thread_monitor = ThreadMonitor() @@ -1510,7 +1511,7 @@ class VmManagerWindow(Ui_VmManagerWindow, QMainWindow): if not thread_monitor.success: QMessageBox.warning(None, self.tr("Error while running command"), - self.tr("Exception while running command:
{0}").format( + unicode(self.tr("Exception while running command:
{0}")).format( thread_monitor.error_msg)) @staticmethod @@ -1725,7 +1726,7 @@ class VmManagerWindow(Ui_VmManagerWindow, QMainWindow): for d in self.blk_manager.attached_devs: if (self.blk_manager.attached_devs[d] ['attached_to']['vm'].qid == vm.qid): - text = self.tr("Detach {dev} {size} {desc}").format( + text = unicode(self.tr("Detach {dev} {size} {desc}")).format( dev=d, size=unicode( self.blk_manager.attached_devs[d]['size']), @@ -1742,7 +1743,7 @@ class VmManagerWindow(Ui_VmManagerWindow, QMainWindow): if d[-1].isdigit() and \ d[0:-1] in self.blk_manager.current_blk: continue - text = self.tr("Attach {dev} {size} {desc}").format( + text = unicode(self.tr("Attach {dev} {size} {desc}")).format( dev=d, size=unicode( self.blk_manager.free_devs[d]['size']), @@ -1868,7 +1869,7 @@ class QubesTrayIcon(QSystemTrayIcon): if len(self.blk_manager.attached_devs) > 0: for d in self.blk_manager.attached_devs: vm = self.blk_manager.attached_devs[d]['attached_to']['vm'] - text = self.tr("Detach {dev} {desc} ({size}) from {vm}").format( + text = unicode(self.tr("Detach {dev} {desc} ({size}) from {vm}")).format( dev=d, desc=self.blk_manager.attached_devs[d]['desc'], size=unicode(self.blk_manager.attached_devs[d]['size']), @@ -1883,7 +1884,7 @@ class QubesTrayIcon(QSystemTrayIcon): # skip partitions heuristic if d[-1].isdigit() and d[0:-1] in self.blk_manager.current_blk: continue - text = self.tr("Attach {dev} {size} {desc}").format( + text = unicode(self.tr("Attach {dev} {size} {desc}")).format( dev=d, size=unicode(self.blk_manager.free_devs[d]['size']), desc=self.blk_manager.free_devs[d]['desc'] diff --git a/qubesmanager/restore.py b/qubesmanager/restore.py index d1429e6..7d99c66 100644 --- a/qubesmanager/restore.py +++ b/qubesmanager/restore.py @@ -272,7 +272,7 @@ class RestoreVMsWindow(Ui_Restore, QWizard): shutil.rmtree(self.tmpdir_to_remove) else: QMessageBox.warning(None, - self.tr("Backup error!"), self.tr("ERROR: {0}") + self.tr("Backup error!"), unicode(self.tr("ERROR: {0}")) .format(self.thread_monitor.error_msg)) if self.showFileDialog.isChecked(): diff --git a/qubesmanager/settings.py b/qubesmanager/settings.py index b507984..ce326fe 100755 --- a/qubesmanager/settings.py +++ b/qubesmanager/settings.py @@ -54,7 +54,7 @@ class VMSettingsWindow(Ui_SettingsDialog, QDialog): self.source_vm = self.vm self.setupUi(self) - self.setWindowTitle(self.tr("Settings: {vm}").format(vm=self.vm.name)) + self.setWindowTitle(unicode(self.tr("Settings: {vm}")).format(vm=self.vm.name)) if init_page in self.tabs_indices: idx = self.tabs_indices[init_page] assert (idx in range(self.tabWidget.count())) @@ -119,7 +119,7 @@ class VMSettingsWindow(Ui_SettingsDialog, QDialog): thread.start() progress = QProgressDialog( - self.tr("Applying settings to {0}...").format(self.vm.name), "", 0, 0) + unicode(self.tr("Applying settings to {0}...")).format(self.vm.name), "", 0, 0) progress.setCancelButton(None) progress.setModal(True) progress.show() @@ -132,8 +132,8 @@ class VMSettingsWindow(Ui_SettingsDialog, QDialog): if not thread_monitor.success: QMessageBox.warning(None, - self.tr("Error while changing settings for {0}!").format(self.vm.name), - self.tr("ERROR: {0}").format(thread_monitor.error_msg)) + unicode(self.tr("Error while changing settings for {0}!")).format(self.vm.name), + unicode(self.tr("ERROR: {0}")).format(thread_monitor.error_msg)) self.done(0) @@ -191,11 +191,11 @@ class VMSettingsWindow(Ui_SettingsDialog, QDialog): if self.vm.netvm is not None and not self.vm.netvm.is_proxyvm(): QMessageBox.warning(None, self.tr("VM configuration problem!"), - self.tr("The '{vm}' AppVM is not network connected to a " + unicode(self.tr("The '{vm}' AppVM is not network connected to a " "FirewallVM!

" "You may edit the '{vm}' VM firewall rules, but these " "will not take any effect until you connect it to " - "a working Firewall VM.").format(vm=self.vm.name)) + "a working Firewall VM.")).format(vm=self.vm.name)) @@ -336,8 +336,8 @@ class VMSettingsWindow(Ui_SettingsDialog, QDialog): msg.append(self.tr("Can't change name of a running VM.")) elif self.qvm_collection.get_vm_by_name(vmname) is not None: msg.append( - self.tr("Can't change VM name - a VM named {0}" - "already exists in the system!").format(vmname)) + unicode(self.tr("Can't change VM name - a VM named {0}" + "already exists in the system!")).format(vmname)) else: oldname = self.vm.name try: @@ -978,7 +978,7 @@ class VMSettingsWindow(Ui_SettingsDialog, QDialog): if port is not None: if port2 is not None and port2 <= port: QMessageBox.warning(None, self.tr("Invalid service ports range"), - self.tr("Port {0} is lower than port {1}.").format( + unicode(self.tr("Port {0} is lower than port {1}.")).format( port2, port)) else: item = {"address": address, @@ -993,7 +993,7 @@ class VMSettingsWindow(Ui_SettingsDialog, QDialog): self.fw_model.appendChild(item) else: QMessageBox.warning(None, self.tr("Invalid service name"), - self.tr("Service '{0}' is unknown.").format(service)) + unicode(self.tr("Service '{0}' is unknown.")).format(service)) # Bases on the original code by: