From d299576a9765d635e8325a6a634e30bb923e3968 Mon Sep 17 00:00:00 2001
From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr>
Date: Mon, 27 Mar 2023 14:55:03 +0200
Subject: [PATCH] ui: Set up translate features.

---
 src/lang/constant_string.py | 83 +++++++++++++++++++++++++++++++++++++
 src/lang/create_ts.sh       | 16 +++++++
 src/pamhyr.py               |  8 +++-
 src/view/MainWindow.py      |  1 +
 src/view/ui/MainWindow.ui   | 77 +++++-----------------------------
 5 files changed, 117 insertions(+), 68 deletions(-)
 create mode 100644 src/lang/constant_string.py
 create mode 100755 src/lang/create_ts.sh

diff --git a/src/lang/constant_string.py b/src/lang/constant_string.py
new file mode 100644
index 00000000..b599389a
--- /dev/null
+++ b/src/lang/constant_string.py
@@ -0,0 +1,83 @@
+# -*- coding: utf-8 -*-
+
+from PyQt5.QtCore import QCoreApplication
+
+_translate = QCoreApplication.translate
+
+
+# -------------------- A --------------------
+
+
+# -------------------- B --------------------
+
+
+# -------------------- C --------------------
+
+
+# -------------------- D --------------------
+
+
+# -------------------- E --------------------
+
+
+# -------------------- F --------------------
+
+
+# -------------------- G --------------------
+
+
+# -------------------- H --------------------
+
+
+# -------------------- I --------------------
+
+
+# -------------------- J --------------------
+
+
+# -------------------- K --------------------
+
+
+# -------------------- L --------------------
+
+
+# -------------------- M --------------------
+
+
+# -------------------- N --------------------
+
+
+# -------------------- O --------------------
+
+
+# -------------------- P --------------------
+
+
+# -------------------- Q --------------------
+
+
+# -------------------- R --------------------
+
+
+# -------------------- S --------------------
+
+
+# -------------------- T --------------------
+
+
+# -------------------- U --------------------
+
+
+# -------------------- V --------------------
+
+
+# -------------------- W --------------------
+
+
+# -------------------- X --------------------
+
+
+# -------------------- Y --------------------
+
+
+# -------------------- Z --------------------
diff --git a/src/lang/create_ts.sh b/src/lang/create_ts.sh
new file mode 100755
index 00000000..c617d22a
--- /dev/null
+++ b/src/lang/create_ts.sh
@@ -0,0 +1,16 @@
+#! /bin/sh
+
+SOURCES=$(find ../ -name "*.py")
+FROM=$(find ../ -name "*.ui")
+
+LANG="fr de"
+
+for l in $LANG
+do
+    pylupdate5 $SOURCES $FROM -ts $l.ts
+done
+
+for l in $LANG
+do
+    lrelease $l.ts $l.qm
+done
diff --git a/src/pamhyr.py b/src/pamhyr.py
index 53a99404..439872a8 100755
--- a/src/pamhyr.py
+++ b/src/pamhyr.py
@@ -1,8 +1,9 @@
 #!/usr/bin/env python3
 # -*- coding: utf-8 -*-
 
-import sys
+import sys, os
 
+from PyQt5.QtCore import QTranslator
 from PyQt5.QtWidgets import QApplication
 
 from config import Config
@@ -12,6 +13,11 @@ from model.Study import Study
 def main():
     conf = Config.load()
     app = QApplication(sys.argv)
+
+    translator = QTranslator()
+    translator.load(os.path.dirname(__file__) + "/lang/fr.qm")
+    app.installTranslator(translator)
+
     application = ApplicationWindow(conf=conf)
     application.show()
     sys.exit(app.exec_())
diff --git a/src/view/MainWindow.py b/src/view/MainWindow.py
index 3f1337ed..24a70235 100644
--- a/src/view/MainWindow.py
+++ b/src/view/MainWindow.py
@@ -61,6 +61,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow):
 
         self.init_callback()
         self.default_style()
+        #self.ui.retranslateUi()
 
     def enable_actions(self, action:str, enable:bool):
         """Enable of disable an action componant
diff --git a/src/view/ui/MainWindow.ui b/src/view/ui/MainWindow.ui
index e9f8b691..8ccb78f6 100644
--- a/src/view/ui/MainWindow.ui
+++ b/src/view/ui/MainWindow.ui
@@ -615,63 +615,6 @@
     </font>
    </property>
   </action>
-  <action name="action_plot_water_line">
-   <property name="text">
-    <string>Ligne d'eau</string>
-   </property>
-  </action>
-  <action name="actionLigne_d_eau_finale">
-   <property name="text">
-    <string>Ligne d'eau finale</string>
-   </property>
-  </action>
-  <action name="actionLigne_d_eau_enveloppe">
-   <property name="text">
-    <string>Ligne d'eau enveloppe</string>
-   </property>
-  </action>
-  <action name="actionVitesse_Pk_t_fix">
-   <property name="text">
-    <string>Vitesse(Pk) à t fixé</string>
-   </property>
-  </action>
-  <action name="actionVitesse_t_Pk_fix">
-   <property name="text">
-    <string>Vitesse(t) à Pk fixé</string>
-   </property>
-  </action>
-  <action name="actionCharge_hydraulique_Pk_t_fix">
-   <property name="text">
-    <string>Charge hydraulique(Pk) à t fixé</string>
-   </property>
-  </action>
-  <action name="actionCharge_hydraulique_t_Pk_fix">
-   <property name="text">
-    <string>Charge hydraulique(t) à Pk fixé</string>
-   </property>
-   <property name="font">
-    <font>
-     <weight>75</weight>
-     <bold>true</bold>
-    </font>
-   </property>
-  </action>
-  <action name="actionVoir_l_animation_MAGE">
-   <property name="text">
-    <string>Voir l'animation (MAGE)</string>
-   </property>
-  </action>
-  <action name="actionAutres_r_sulats_MAGE">
-   <property name="text">
-    <string>Autres résulats MAGE</string>
-   </property>
-   <property name="font">
-    <font>
-     <weight>75</weight>
-     <bold>true</bold>
-    </font>
-   </property>
-  </action>
   <action name="action_map_current_reach">
    <property name="text">
     <string>Map current reach</string>
@@ -758,7 +701,7 @@
     <string>Run solver</string>
    </property>
    <property name="toolTip">
-    <string>Lancer le solveur pour réaliser une simulation</string>
+    <string>Run solver on current study</string>
    </property>
    <property name="shortcut">
     <string>Ctrl+X</string>
@@ -791,7 +734,7 @@
     <string>Run external meshing tool</string>
    </property>
    <property name="toolTip">
-    <string>Lancer le mailleur externe sur la géométrie du bief courant</string>
+    <string>Run meshing tool on current reach geometry</string>
    </property>
   </action>
   <action name="action_toolBar_listing">
@@ -806,7 +749,7 @@
     <string>Display simulation listing</string>
    </property>
    <property name="toolTip">
-    <string>Aficher les listings de la simulation courante</string>
+    <string>Display current simulation listing</string>
    </property>
   </action>
   <action name="action_toolBar_network">
@@ -818,7 +761,7 @@
     <string>River network</string>
    </property>
    <property name="toolTip">
-    <string>Open river network edition</string>
+    <string>Edit river network</string>
    </property>
   </action>
   <action name="action_toolBar_geometry">
@@ -830,7 +773,7 @@
     <string>Geometry</string>
    </property>
    <property name="toolTip">
-    <string>Open geometry edition</string>
+    <string>Edit reach geometry</string>
    </property>
   </action>
   <action name="action_toolBar_mesh">
@@ -861,7 +804,7 @@
     <string>Lateral contribution</string>
    </property>
    <property name="toolTip">
-    <string>Ouvrir l'éditeur des Apports Latéraux Distribués</string>
+    <string>Edit lateral contribution</string>
    </property>
   </action>
   <action name="action_toolBar_spills">
@@ -869,7 +812,7 @@
     <string>Spills</string>
    </property>
    <property name="toolTip">
-    <string>Ouvrir l'éditeur des Déversements Latéraux</string>
+    <string>Edit lateral spills</string>
    </property>
   </action>
   <action name="action_toolBar_sections">
@@ -877,7 +820,7 @@
     <string>Sections</string>
    </property>
    <property name="toolTip">
-    <string>Ouvrir l'éditeur des tronçons pour les frottements et Apports Latéraux</string>
+    <string>Edit section frictions and lateral contributions</string>
    </property>
   </action>
   <action name="action_toolBar_frictions">
@@ -885,7 +828,7 @@
     <string>Frictions</string>
    </property>
    <property name="toolTip">
-    <string>Ouvrir l'éditeur des frottements au fond</string>
+    <string>Edit friction at the bottom</string>
    </property>
   </action>
   <action name="action_toolBar_building">
@@ -893,7 +836,7 @@
     <string>Building</string>
    </property>
    <property name="toolTip">
-    <string>Ouvrir l'éditeur des ouvrages (seuils, vannes, etc.), singularités et pompes</string>
+    <string>Edit building (valve, ...), singularity and pump</string>
    </property>
   </action>
   <action name="action_menu_edit">
-- 
GitLab