Commit 495f8898 authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

ui: Set language at starup and change during execution (don't works).

Showing with 65 additions and 9 deletions
+65 -9
......@@ -3,7 +3,7 @@
SOURCES=$(find ../ -name "*.py")
FROM=$(find ../ -name "*.ui")
LANG="fr de"
LANG="fr"
for l in $LANG
do
......
......@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
import sys, os
import locale
from PyQt5.QtCore import QTranslator
from PyQt5.QtWidgets import QApplication
......@@ -15,7 +16,9 @@ def main():
app = QApplication(sys.argv)
translator = QTranslator()
translator.load(os.path.dirname(__file__) + "/lang/fr.qm")
lang = locale.getdefaultlocale()
if "fr" not in lang[0]:
translator.load(os.path.dirname(__file__) + "/lang/fr.qm")
app.installTranslator(translator)
application = ApplicationWindow(conf=conf)
......
......@@ -3,6 +3,9 @@
import os
from PyQt5 import QtGui
from PyQt5.QtCore import (
QTranslator, QEvent
)
from PyQt5.QtWidgets import (
QMainWindow, QApplication, QAction,
QFileDialog,
......@@ -61,6 +64,8 @@ class ApplicationWindow(QMainWindow, ListedSubWindow):
self.init_callback()
self.default_style()
self.trans = QTranslator(self)
#self.ui.retranslateUi()
def enable_actions(self, action:str, enable:bool):
......@@ -110,12 +115,36 @@ class ApplicationWindow(QMainWindow, ListedSubWindow):
"action_toolBar_sections": lambda: self.open_dummy("Tronçons"),
"action_toolBar_frictions": lambda: self.open_dummy("Frottements"),
"action_toolBar_building": lambda: self.open_dummy("Ouvrages"),
## Language
"action_english": lambda: self.set_language(""),
"action_french": lambda: self.set_language("fr"),
}
for action in actions:
self.ui.findChild(QAction, action)\
.triggered.connect(actions[action])
def set_language(self, lang):
if lang != "":
translator = QTranslator()
translator.load(os.path.dirname(__file__) + f"/lang/{lang}.qm")
QApplication.instance().installTranslator(translator)
self.trans = translator
else:
QApplication.instance().removeTranslator(self.trans)
self.retranslateUi()
def retranslateUi(self):
for action in self.menubar.children():
if isinstance(action, QAction):
action.setText(self.trans("MainWindow", action.getText()))
def changeEvent(self, event):
if event.type() == QEvent.LanguageChange:
self.retranslateUi()
super(ApplicationWindow, self).changeEvent(event)
def default_style(self):
"""Set default window style
......
......@@ -13,6 +13,9 @@
<property name="windowTitle">
<string>Dialog</string>
</property>
<property name="locale">
<locale language="English" country="Europe"/>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
......@@ -106,7 +109,7 @@
</widget>
<widget class="QWidget" name="tab_mailleur">
<attribute name="title">
<string>Mailleur</string>
<string>Meshing tool</string>
</attribute>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
......@@ -121,7 +124,7 @@
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Mailleur path</string>
<string>Meshing tool path</string>
</property>
</widget>
</item>
......@@ -161,14 +164,14 @@
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Nombre de segment</string>
<string>Segment number</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Taille max. du listing</string>
<string>Listing maximum size</string>
</property>
</widget>
</item>
......@@ -214,14 +217,14 @@
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>Sauvegarde automatique</string>
<string>Auto save</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_8">
<property name="text">
<string>Chemin</string>
<string>Path</string>
</property>
</widget>
</item>
......@@ -246,7 +249,7 @@
<item>
<widget class="QCheckBox" name="checkBox_backup">
<property name="text">
<string>Activé</string>
<string>Enable</string>
</property>
<property name="tristate">
<bool>false</bool>
......
......@@ -201,6 +201,16 @@
<addaction name="action_menu_help_mage"/>
<addaction name="action_menu_about"/>
</widget>
<widget class="QMenu" name="menu_language">
<property name="locale">
<locale language="English" country="Europe"/>
</property>
<property name="title">
<string>&amp;Language</string>
</property>
<addaction name="action_english"/>
<addaction name="action_french"/>
</widget>
<addaction name="menu_File"/>
<addaction name="menu_network"/>
<addaction name="menu_geometry"/>
......@@ -208,6 +218,7 @@
<addaction name="menu_run"/>
<addaction name="menu_plot"/>
<addaction name="menu_cartography"/>
<addaction name="menu_language"/>
<addaction name="menu_help"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
......@@ -851,6 +862,16 @@
<string>Edit study</string>
</property>
</action>
<action name="action_english">
<property name="text">
<string>English</string>
</property>
</action>
<action name="action_french">
<property name="text">
<string>French</string>
</property>
</action>
</widget>
<resources/>
<connections>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment