From 38243f13610334c7bf0037b7a3fbe6240d1a02ef Mon Sep 17 00:00:00 2001 From: bordoray Date: Wed, 11 Sep 2024 09:47:28 +0900 Subject: [PATCH 1/5] UI in english --- ui/main_dialog.ui | 10 +++++----- ui/progress_dialog.ui | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ui/main_dialog.ui b/ui/main_dialog.ui index 42bd288..1397575 100644 --- a/ui/main_dialog.ui +++ b/ui/main_dialog.ui @@ -17,7 +17,7 @@ - レイヤー設定 + Layers to export @@ -39,7 +39,7 @@ - マップ設定 + Map parameters @@ -48,7 +48,7 @@ - 出力縮尺 + Output Scale @@ -70,14 +70,14 @@ - 出力フォルダーを選択して実行 + Select the output folder and execute - キャンセル + Cancel diff --git a/ui/progress_dialog.ui b/ui/progress_dialog.ui index e2eadc5..60f5f99 100644 --- a/ui/progress_dialog.ui +++ b/ui/progress_dialog.ui @@ -17,7 +17,7 @@ - 処理中... + Processing... @@ -48,7 +48,7 @@ - テキスト + Text Qt::AlignCenter @@ -66,7 +66,7 @@ - 中断 + Abort From fc0f60cd7eb1b44211c5834b77d26d463a23ade2 Mon Sep 17 00:00:00 2001 From: bordoray Date: Wed, 11 Sep 2024 09:57:32 +0900 Subject: [PATCH 2/5] Help button to readme page --- ui/main_dialog.py | 8 ++++++++ ui/main_dialog.ui | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/ui/main_dialog.py b/ui/main_dialog.py index 01c5dc1..af9d931 100644 --- a/ui/main_dialog.py +++ b/ui/main_dialog.py @@ -2,6 +2,8 @@ import shutil import sip +import webbrowser + from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QDialog, QMessageBox, QTreeWidgetItem, QFileDialog from qgis.PyQt.QtGui import QIcon @@ -39,6 +41,7 @@ def init_ui(self): # connect signals self.ui.pushButton_run.clicked.connect(self._run) self.ui.pushButton_cancel.clicked.connect(self.close) + self.ui.pushButton_help.clicked.connect(self._on_help_button_clicked) # QgsExtentGroupBox self.ui.mExtentGroupBox.setMapCanvas(iface.mapCanvas()) @@ -317,3 +320,8 @@ def _zoom_canvas_from_scale(self): # reactive scale auto-calculation when extent changed self.enable_update_ui_scale = True + + def _on_help_button_clicked(self): + # show readme page + webbrowser.open("https://github.com/MIERUNE/qgis-plugx-plugin") + return diff --git a/ui/main_dialog.ui b/ui/main_dialog.ui index 1397575..96f25fa 100644 --- a/ui/main_dialog.ui +++ b/ui/main_dialog.ui @@ -81,6 +81,13 @@ + + + + Help + + + From 2315b3971d78111e7d42079e84c49bbc7fc03ed3 Mon Sep 17 00:00:00 2001 From: bordoray Date: Wed, 11 Sep 2024 11:25:58 +0900 Subject: [PATCH 3/5] Process messages to english --- translator/thread.py | 6 +++++- ui/main_dialog.py | 31 +++++++++++++++++++------------ ui/progress_dialog.py | 21 ++++++++++++++++----- 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/translator/thread.py b/translator/thread.py index e4deb74..2bacc82 100644 --- a/translator/thread.py +++ b/translator/thread.py @@ -5,6 +5,8 @@ from translator.vector.process import process_vector from translator.vector.label import generate_label_json +from ui.progress_dialog import ProgressDialog + class ProcessingThread(QThread): processStarted = pyqtSignal(int) @@ -53,7 +55,9 @@ def run(self): self.results.append(result) # emit progress - self.postMessage.emit(f"処理中: {layer.name()}") + self.postMessage.emit( + f"{ProgressDialog.translate("Processing: ")} {layer.name()}" + ) self.setAbortable.emit(True) self.addProgress.emit(1) except Exception as e: diff --git a/ui/main_dialog.py b/ui/main_dialog.py index af9d931..d9e0838 100644 --- a/ui/main_dialog.py +++ b/ui/main_dialog.py @@ -101,7 +101,9 @@ def _run(self): lambda error_message: [ QgsMessageLog.logMessage(error_message, "QGS2PlugX", Qgis.Critical), QMessageBox.information( - self, "エラー", f"エラーが発生しました。\n\n{error_message}" + self, + self.tr("Error"), + f"{self.tr("An error occured.")}\n\n{error_message}", ), # noqa progress_dialog.close(), ] @@ -163,19 +165,22 @@ def _run(self): ) # messaging - msg = f"処理が完了しました。\n\n出力先:\n{params['output_dir']}" + msg = self.tr("Process completed") + msg += f"\n\n{self.tr("Output folder")}:\n{params['output_dir']}" + if len(layers_has_unsupported_symbol) > 0: - msg += ( - "\n\n以下レイヤに対応不可なシンボロジがあるため、\n\ - シンプルシンボルに変換しました。\n" - + "\n".join(layers_has_unsupported_symbol) - ) + msg += "\n\n" + msg += self.tr("The following layers contains unsupported symbols") + msg += self.tr("and have been converted to simple symbols.") + msg += "\n\n".join(layers_has_unsupported_symbol) + if len(layers_not_completed) > 0: - msg += "\n\n以下のレイヤーは出力できませんでした。\n" - msg += "\n".join(layers_not_completed) + msg += "\n\n" + msg += self.tr("Failed to export the following layers.") + msg += "\n\n".join(layers_not_completed) QMessageBox.information( None, - "完了", + self.tr("Completed"), msg, ) @@ -186,8 +191,10 @@ def _run(self): except PermissionError: QMessageBox.warning( self, - "エラー", - "一時フォルダの削除に失敗しました。\n手動で削除してください。", + self.tr("Error"), + self.tr( + "Failed to delete the temporary folder. Please delete it manually." + ), ) def _get_checked_layers(self): diff --git a/ui/progress_dialog.py b/ui/progress_dialog.py index 17f2c7c..cb6db96 100644 --- a/ui/progress_dialog.py +++ b/ui/progress_dialog.py @@ -25,11 +25,11 @@ def __init__(self, set_abort_flag_callback): self.init_ui() def init_ui(self): - self.label.setText("処理開始中...") + self.label.setText(self.tr("Initializing process...")) self.progressBar.setValue(0) self.progressBar.setMaximum(0) self.abortButton.setEnabled(True) - self.abortButton.setText("中断") + self.abortButton.setText(self.tr("Cancel")) self.abortButton.clicked.connect(self.on_abort_click) def keyPressEvent(self, event: QKeyEvent): @@ -40,15 +40,15 @@ def keyPressEvent(self, event: QKeyEvent): def on_abort_click(self): if QMessageBox.Yes == QMessageBox.question( self, - "確認", - "処理を中断し、以降の処理をスキップしてよろしいですか?", + self.tr("Check"), + self.tr("Are you sure to abort the process?")", QMessageBox.Yes, QMessageBox.No, ): if self.abortButton.isEnabled(): # abort if possible self.set_abort_flag_callback() self.abortButton.setEnabled(False) - self.abortButton.setText("中断待機中...") + self.abortButton.setText(self.tr("Aborting...")) def set_maximum(self, value: int): self.progressBar.setMaximum(value) @@ -61,3 +61,14 @@ def set_messsage(self, message: str): def set_abortable(self, abortable=True): self.abortButton.setEnabled(abortable) + + def translate(self, message): + """translate messages coming from outside UI""" + message_dic = { + "Processing: ": self.tr("Processing: "), + } + translated_message = message_dic.get( + message, message + ) # fallback is self message + + return translated_message \ No newline at end of file From 1552612f068db6e9205231311fd4b8e77405cca2 Mon Sep 17 00:00:00 2001 From: bordoray Date: Wed, 11 Sep 2024 13:35:49 +0900 Subject: [PATCH 4/5] i18n en/ja --- i18n/QGIS2PlugX_en.ts | 142 +++++++++++++++++++++++++++++++++++++++++ i18n/QGIS2PlugX_ja.qm | Bin 0 -> 1836 bytes i18n/QGIS2PlugX_ja.ts | 143 ++++++++++++++++++++++++++++++++++++++++++ qgis2plugx.pro | 7 +++ qgis2plugx.py | 14 +++++ translator/thread.py | 4 +- ui/main_dialog.py | 6 +- ui/progress_dialog.py | 6 +- 8 files changed, 314 insertions(+), 8 deletions(-) create mode 100644 i18n/QGIS2PlugX_en.ts create mode 100644 i18n/QGIS2PlugX_ja.qm create mode 100644 i18n/QGIS2PlugX_ja.ts create mode 100644 qgis2plugx.pro diff --git a/i18n/QGIS2PlugX_en.ts b/i18n/QGIS2PlugX_en.ts new file mode 100644 index 0000000..5097ba3 --- /dev/null +++ b/i18n/QGIS2PlugX_en.ts @@ -0,0 +1,142 @@ + + + + Dialog + + + Dialog + + + + + Layers to export + + + + + Map parameters + + + + + Output Scale + + + + + Select the output folder and execute + + + + + Cancel + + + + + Help + + + + + Processing... + + + + + %v/%m + + + + + Text + + + + + Abort + + + + + MainDialog + + + Error + + + + + Process completed + + + + + The following layers contains unsupported symbols + + + + + and have been converted to simple symbols. + + + + + Failed to export the following layers. + + + + + Completed + + + + + Failed to delete the temporary folder. Please delete it manually. + + + + + An error occured. + + + + + Output folder + + + + + ProgressDialog + + + Initializing process... + + + + + Cancel + + + + + Check + + + + + Are you sure to abort the process? + + + + + Aborting... + + + + + Processing: + + + + diff --git a/i18n/QGIS2PlugX_ja.qm b/i18n/QGIS2PlugX_ja.qm new file mode 100644 index 0000000000000000000000000000000000000000..35c4b212f7946aebad2d4ba37d00b1ba4924a201 GIT binary patch literal 1836 zcmaJ>U2GIp6u#T;F56#AG-3j#7ejb3baQwBlg41SElOd#rCS8+8kgCb+wHWoGsDcC zy2}I62Mqy93`(Oy5TYg$tZzmXw3sHwV0Whe#b7!{GWjc_}?(Dtu z-SeIMo$s6{&nS;vxOwcz_p4V;?LPVC)h4%chEXRI9iZQc7A_fq_;>xi%WXW4V3FA@^nnKdvss&g-)NPx!>WY!|9+b zX)FkD9=OiqnGTW^AOA?pcFT~NZL4}QnM?-HtP&J(5l-Q~&%$D^DKK$mP&Ofv~rBh~EhD8lob}Xj2cWCUBRK2Fi(cJ5q*ZeaL-A2jOP*X+RH;9dU zj6OQHS%eQmc4o+Mm#>bV-8!Mb*wA{mYcbElw(LbHx^GZ5=!f0#EcDdmpL$wSHKqt- zD5xT5u8N$M&?J&op`MUQx?N+E%@!~!rzJ^uBu%S?-gj+gHq!+9f)&AV>sW+7)Gr5b zLNTD?+Qlq9d%9U5w`RPA&Y+s>-cYKz2tBaHm#d}fK`-$z*&Y%`gtREhqEP<%TXU105Q?6%y$j?P60$ zw;fY7C)UHRlnRFC_FT{))Mc5$mhjl-u;>l)<&e8PF8n_tjWb$cOczAs%#DuKwpHQ5 z1)fl8+r;?FzdD*<(zQ+QC|m5=RurvhVH?+Yexob%VG#pUi)3ae`at*gugrzM*J^^*i5AA15RouS&G4)m56^efumtV^ DfJEvl literal 0 HcmV?d00001 diff --git a/i18n/QGIS2PlugX_ja.ts b/i18n/QGIS2PlugX_ja.ts new file mode 100644 index 0000000..26c94a3 --- /dev/null +++ b/i18n/QGIS2PlugX_ja.ts @@ -0,0 +1,143 @@ + + + + + Dialog + + + Dialog + + + + + Layers to export + レイヤー設定 + + + + Map parameters + マップ設定 + + + + Output Scale + 出力縮尺 + + + + Select the output folder and execute + 出力フォルダーを選択して実行 + + + + Cancel + キャンセル + + + + Help + ヘルプ + + + + Processing... + 処理中... + + + + %v/%m + + + + + Text + テキスト + + + + Abort + 中断 + + + + MainDialog + + + Error + エラー + + + + Process completed + 処理が完了しました。 + + + + The following layers contains unsupported symbols + 以下レイヤに対応不可なシンボロジがあるため、 + + + + and have been converted to simple symbols. + シンプルシンボルに変換しました。 + + + + Failed to export the following layers. + 以下のレイヤーは出力できませんでした。 + + + + Completed + 完了 + + + + Failed to delete the temporary folder. Please delete it manually. + 一時フォルダの削除に失敗しました。手動で削除してください。 + + + + An error occured. + エラーが発生しました。 + + + + Output folder + 出力先 + + + + ProgressDialog + + + Initializing process... + 処理開始中... + + + + Cancel + 中断 + + + + Check + 確認 + + + + Are you sure to abort the process? + 処理を中断し、以降の処理をスキップしてよろしいですか? + + + + Aborting... + 中断待機中... + + + + Processing: + 処理中: + + + diff --git a/qgis2plugx.pro b/qgis2plugx.pro new file mode 100644 index 0000000..1dad048 --- /dev/null +++ b/qgis2plugx.pro @@ -0,0 +1,7 @@ +SOURCES += qgis2plugx.py \ + ui/main_dialog.py \ + ui/progress_dialog.py + +FORMS += ./ui/main_dialog.ui ./ui/progress_dialog.ui + +TRANSLATIONS = ./i18n/QGIS2PlugX_ja.ts ./i18n/QGIS2PlugX_en.ts \ No newline at end of file diff --git a/qgis2plugx.py b/qgis2plugx.py index 82b869e..8cca081 100644 --- a/qgis2plugx.py +++ b/qgis2plugx.py @@ -2,6 +2,7 @@ from PyQt5.QtGui import QIcon from PyQt5.QtWidgets import QAction +from PyQt5.QtCore import QSettings, QTranslator, QCoreApplication from qgis.gui import QgisInterface from ui.main_dialog import MainDialog @@ -25,6 +26,19 @@ def __init__(self, iface: QgisInterface): self.main_dialog = None self.about_dialog = None + locale = QSettings().value("locale/userLocale")[0:2] + locale_path = os.path.join( + self.plugin_dir, "i18n", "QGIS2PlugX_{}.qm".format(locale) + ) + + if os.path.exists(locale_path): + self.translator = QTranslator() + self.translator.load(locale_path) + QCoreApplication.installTranslator(self.translator) + + def tr(self, message): + return QCoreApplication.translate("QGIS2PlugX", message) + def add_action( self, icon_path, diff --git a/translator/thread.py b/translator/thread.py index 2bacc82..159543c 100644 --- a/translator/thread.py +++ b/translator/thread.py @@ -55,9 +55,7 @@ def run(self): self.results.append(result) # emit progress - self.postMessage.emit( - f"{ProgressDialog.translate("Processing: ")} {layer.name()}" - ) + self.postMessage.emit("Processing: " + layer.name()) self.setAbortable.emit(True) self.addProgress.emit(1) except Exception as e: diff --git a/ui/main_dialog.py b/ui/main_dialog.py index d9e0838..965bf7b 100644 --- a/ui/main_dialog.py +++ b/ui/main_dialog.py @@ -103,7 +103,7 @@ def _run(self): QMessageBox.information( self, self.tr("Error"), - f"{self.tr("An error occured.")}\n\n{error_message}", + self.tr("An error occured.") + f"\n\n{error_message}", ), # noqa progress_dialog.close(), ] @@ -166,7 +166,9 @@ def _run(self): # messaging msg = self.tr("Process completed") - msg += f"\n\n{self.tr("Output folder")}:\n{params['output_dir']}" + msg += f"\n\n" + msg += self.tr("Output folder") + msg += f":\n{params['output_dir']}" if len(layers_has_unsupported_symbol) > 0: msg += "\n\n" diff --git a/ui/progress_dialog.py b/ui/progress_dialog.py index cb6db96..f1df6f5 100644 --- a/ui/progress_dialog.py +++ b/ui/progress_dialog.py @@ -41,7 +41,7 @@ def on_abort_click(self): if QMessageBox.Yes == QMessageBox.question( self, self.tr("Check"), - self.tr("Are you sure to abort the process?")", + self.tr("Are you sure to abort the process?"), QMessageBox.Yes, QMessageBox.No, ): @@ -62,7 +62,7 @@ def set_messsage(self, message: str): def set_abortable(self, abortable=True): self.abortButton.setEnabled(abortable) - def translate(self, message): + def translate(self, message: str): """translate messages coming from outside UI""" message_dic = { "Processing: ": self.tr("Processing: "), @@ -71,4 +71,4 @@ def translate(self, message): message, message ) # fallback is self message - return translated_message \ No newline at end of file + return translated_message From cfa0e57189be3f1430387842dcdb50284682321d Mon Sep 17 00:00:00 2001 From: bordoray Date: Wed, 11 Sep 2024 13:47:46 +0900 Subject: [PATCH 5/5] Lint --- translator/thread.py | 2 -- ui/main_dialog.py | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/translator/thread.py b/translator/thread.py index 159543c..499834a 100644 --- a/translator/thread.py +++ b/translator/thread.py @@ -5,8 +5,6 @@ from translator.vector.process import process_vector from translator.vector.label import generate_label_json -from ui.progress_dialog import ProgressDialog - class ProcessingThread(QThread): processStarted = pyqtSignal(int) diff --git a/ui/main_dialog.py b/ui/main_dialog.py index 965bf7b..4c69eb8 100644 --- a/ui/main_dialog.py +++ b/ui/main_dialog.py @@ -166,7 +166,7 @@ def _run(self): # messaging msg = self.tr("Process completed") - msg += f"\n\n" + msg += "\n\n" msg += self.tr("Output folder") msg += f":\n{params['output_dir']}"