diff --git a/Makefile b/Makefile index 9066e20..c8a9315 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,19 @@ .PHONY: gui gui: relational_gui/survey.py relational_gui/maingui.py relational_gui/rel_edit.py relational_gui/resources.py -relational_gui/survey.py: - pyuic5 relational_gui/survey.ui > relational_gui/survey.py - -relational_gui/maingui.py: - pyuic5 relational_gui/maingui.ui > relational_gui/maingui.py - sed -i 's/QtWidgets.QPlainTextEdit/editor.Editor/g' relational_gui/maingui.py - echo 'from . import editor' >> relational_gui/maingui.py - -relational_gui/rel_edit.py: - pyuic5 relational_gui/rel_edit.ui > relational_gui/rel_edit.py +relational_gui/maingui.py relational_gui/survey.py relational_gui/rel_edit.py: + # Create .py file + pyuic5 $(basename $@).ui > $@ + # Use my custom editor class + sed -i 's/QtWidgets.QPlainTextEdit/editor.Editor/g' $@ + echo 'from . import editor' >> $@ + # Use gettext instead of Qt translations + echo 'from gettext import gettext as _' >> $@ + sed -i \ + -e 's/_translate("MainWindow", /_(/g' \ + -e 's/_translate("Dialog", /_(/g' \ + -e 's/_translate("Form", /_(/g' \ + $@ relational_gui/resources.py: pyrcc5 relational_gui/resources.qrc > relational_gui/resources.py diff --git a/relational_gui/creator.py b/relational_gui/creator.py index 42b87f5..d783c8b 100644 --- a/relational_gui/creator.py +++ b/relational_gui/creator.py @@ -16,6 +16,8 @@ # # author Salvo "LtWorf" Tomaselli +from gettext import gettext as _ + from PyQt5 import QtGui, QtWidgets from relational_gui import rel_edit @@ -86,8 +88,8 @@ class creatorForm(QtWidgets.QDialog): try: header = relation.Header(h) except Exception as e: - QtWidgets.QMessageBox.information(None, QtWidgets.QApplication.translate("Form", "Error"), "%s\n%s" % ( - QtWidgets.QApplication.translate("Form", "Header error!"), e.__str__())) + QtWidgets.QMessageBox.information(None, _("Error"), "%s\n%s" % ( + _("Header error!"), e.__str__())) return None content = [] @@ -97,8 +99,7 @@ class creatorForm(QtWidgets.QDialog): try: hlist.append(self.table.item(i, j).text()) except: - QtWidgets.QMessageBox.information(None, QtWidgets.QApplication.translate( - "Form", "Error"), QtWidgets.QApplication.translate("Form", "Unset value in %d,%d!" % (i + 1, j + 1))) + QtWidgets.QMessageBox.information(None, _("Error"), _(f'Unset value in {i + 1},{j + 1}!')) return None content.append(hlist) return relation.Relation.create_from(header, content) diff --git a/relational_gui/guihandler.py b/relational_gui/guihandler.py index d989082..d8ba220 100644 --- a/relational_gui/guihandler.py +++ b/relational_gui/guihandler.py @@ -16,6 +16,7 @@ # # author Salvo "LtWorf" Tomaselli import sys +from gettext import gettext as _ from PyQt5 import QtCore, QtWidgets, QtGui @@ -115,19 +116,15 @@ class relForm(QtWidgets.QMainWindow): online = maintenance.check_latest_version() if online is None: - r = QtWidgets.QApplication.translate("Form", "Network error") + r = _('Network error') elif online > version: - r = QtWidgets.QApplication.translate( - "Form", "New version available online: %s." % online) + r = _(f'New version available online: {online}.') elif online == version: - r = QtWidgets.QApplication.translate( - "Form", "Latest version installed.") + r = _('Latest version installed.') else: - r = QtWidgets.QApplication.translate( - "Form", "You are using an unstable version.") + r = _('You are using an unstable version.') - QtWidgets.QMessageBox.information( - self, QtWidgets.QApplication.translate("Form", "Version"), r) + QtWidgets.QMessageBox.information(_('Version'), r) def setHistoryShown(self, history_shown): self.history_shown = history_shown @@ -241,7 +238,7 @@ class relForm(QtWidgets.QMainWindow): if rel is None: # No relation to show self.ui.table.setColumnCount(1) - self.ui.table.headerItem().setText(0, "Empty relation") + self.ui.table.headerItem().setText(0, _('Empty relation')) return self.ui.table.setColumnCount(len(rel.header)) @@ -282,17 +279,14 @@ class relForm(QtWidgets.QMainWindow): def saveRelation(self): if not self.ui.lstRelations.selectedItems(): - r = QtWidgets.QApplication.translate( - "Form", "Select a relation first." - ) QtWidgets.QMessageBox.information( - self, QtWidgets.QApplication.translate("Form", "Error"), r + self, _('Error'), _('Select a relation first.') ) return filename = QtWidgets.QFileDialog.getSaveFileName( - self, QtWidgets.QApplication.translate("Form", "Save Relation"), + self, _("Save Relation"), "", - QtWidgets.QApplication.translate("Form", "Json relations (*.json);;CSV relations (*.csv)") + _("Json relations (*.json);;CSV relations (*.csv)") )[0] if (len(filename) == 0): # Returns if no file was selected return @@ -318,7 +312,7 @@ class relForm(QtWidgets.QMainWindow): ) except Exception as e: QtWidgets.QMessageBox.warning( - self, QtWidgets.QApplication.translate("Form", "Error"), str(e) + self, _("Error"), str(e) ) return if result != None: @@ -328,7 +322,7 @@ class relForm(QtWidgets.QMainWindow): def error(self, exception): print (exception) QtWidgets.QMessageBox.information( - None, QtWidgets.QApplication.translate("Form", "Error"), + None, _("Error"), str(exception) ) @@ -336,21 +330,16 @@ class relForm(QtWidgets.QMainWindow): while True: res = QtWidgets.QInputDialog.getText( self, - QtWidgets.QApplication.translate("Form", "New relation"), - QtWidgets.QApplication.translate( - "Form", "Insert the name for the new relation"), + _("New relation"), + _("Insert the name for the new relation"), QtWidgets.QLineEdit.Normal, '' ) if res[1] == False: # or len(res[0]) == 0: return None name = res[0] if not rtypes.is_valid_relation_name(name): - r = QtWidgets.QApplication.translate( - "Form", str( - "Wrong name for destination relation: %s." % name) - ) QtWidgets.QMessageBox.information( - self, QtWidgets.QApplication.translate("Form", "Error"), r + self, _("Error"), _('Wrong name for destination relation: {name}.') ) continue return name @@ -418,12 +407,9 @@ class relForm(QtWidgets.QMainWindow): if not filenames: f = QtWidgets.QFileDialog.getOpenFileNames( self, - QtWidgets.QApplication.translate("Form", "Load Relation"), + _("Load Relation"), "", - QtWidgets.QApplication.translate( - "Form", - "Relations (*.json *.csv);;Text Files (*.txt);;All Files (*)" - ) + _("Relations (*.json *.csv);;Text Files (*.txt);;All Files (*)") ) filenames = f[0] diff --git a/relational_gui/surveyForm.py b/relational_gui/surveyForm.py index a638392..1050d6a 100644 --- a/relational_gui/surveyForm.py +++ b/relational_gui/surveyForm.py @@ -1,5 +1,5 @@ # Relational -# Copyright (C) 2008-2017 Salvo "LtWorf" Tomaselli +# Copyright (C) 2008-2020 Salvo "LtWorf" Tomaselli # # Relational is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -18,6 +18,7 @@ import platform import locale +from gettext import gettext as _ from PyQt5 import QtWidgets @@ -86,13 +87,10 @@ class surveyForm (QtWidgets.QWidget): response = maintenance.send_survey(post) if response == 200: - QtWidgets.QMessageBox.information(None, QtWidgets.QApplication.translate( - "Form", "Thanks"), QtWidgets.QApplication.translate("Form", "Thanks for sending!")) + QtWidgets.QMessageBox.information(None, _('Thanks'), _('Thanks for sending!')) elif response == -1: - QtWidgets.QMessageBox.information(None, QtWidgets.QApplication.translate( - "Form", "Seriously?"), QtWidgets.QApplication.translate("Form", "Yeah, not sending that.")) + QtWidgets.QMessageBox.information(None, _('Seriously?'), _('Yeah, not sending that.')) else: - QtWidgets.QMessageBox.information(None, QtWidgets.QApplication.translate( - "Form", "Error"), QtWidgets.QApplication.translate("Form", "Unable to send the data!")) + QtWidgets.QMessageBox.information(None, _('Error'), _('Unable to send the data!')) self.hide()