Commit 4cfbe44c authored by Antoine Lima's avatar Antoine Lima
Browse files

Auto-translating software

parent 9ab100f3
......@@ -11,7 +11,7 @@ import sys
import logging
from os.path import dirname, abspath, join
from PyQt5 import QtWidgets, QtCore
from PyQt5 import QtCore
from PyQt5.QtWidgets import QMainWindow, QApplication
def getContent(path):
......@@ -28,11 +28,10 @@ def getMainWin():
return None
if __name__=='__main__':
print(__package__)
__package__ = 'Babyfut'
from Babyfut.ui.mainwin import MainWin
from Babyfut.modules import GameModule
from Babyfut.core.player import Side
from Babyfut.core.settings import Settings
from Babyfut.core.input import GPIOThread
from Babyfut.core.database import Database
from Babyfut.core.replay import Replay as ReplayThread
......@@ -41,12 +40,7 @@ if __name__=='__main__':
#logging.basicConfig(filename='babyfoot.log', level=logging.DEBUG)
logging.basicConfig(level=logging.DEBUG)
app = QtWidgets.QApplication(sys.argv)
lang = Settings['ui.language']
qtTranslator = QtCore.QTranslator()
if lang!='en' and qtTranslator.load("translations/babyfut_{}.qm".format(lang)):
app.installTranslator(qtTranslator)
app = QApplication(sys.argv)
myapp = MainWin()
if ReplayThread.isCamAvailable():
......
......@@ -38,6 +38,7 @@ class Module(QWidget):
# Select first element of the Module
self.mainwin.modules[newmod_idx].focusNextChild()
self.mainwin.modules[newmod_idx].focusPreviousChild()
self.mainwin.modules[newmod_idx].ui.retranslateUi(self.mainwin)
self.mainwin.modules[newmod_idx].load()
def send(self, to, **kwargs):
......
......@@ -245,6 +245,21 @@
<source>Privacy</source>
<translation>Vie Privée</translation>
</message>
<message>
<location filename="../modules/authleague.py" line="51"/>
<source>{} Victories</source>
<translation>{} Victoires</translation>
</message>
<message>
<location filename="../modules/authleague.py" line="52"/>
<source>{} Games Played</source>
<translation>{} Parties Jouées</translation>
</message>
<message>
<location filename="../modules/authleague.py" line="53"/>
<source>{} Goals Scored</source>
<translation>{} Buts Marqués</translation>
</message>
<message encoding="UTF-8">
<location filename="../ui/options_ui.py" line="229"/>
<source>Français</source>
......
......@@ -5,20 +5,28 @@
"""
import os
from os.path import join, dirname, abspath
import logging
OnRasp = os.uname()[1] == 'raspberrypi'
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QGraphicsBlurEffect, QApplication
from PyQt5.QtCore import QTime, Qt
from PyQt5.QtCore import Qt, QTime, QTranslator
from Babyfut.ui.main_ui import Ui_MainWindow
from Babyfut import modules
from Babyfut.ui.main_ui import Ui_MainWindow
from Babyfut.core.settings import Settings
class MainWin(QtWidgets.QMainWindow):
DEFAULT_LANG = 'en'
TR_PATH = join(dirname(dirname(abspath(__file__))), 'translations/')
def __init__(self, parent=None):
QtWidgets.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.lang = MainWin.DEFAULT_LANG
self._retranslateUI()
#Background blur
bgBlur = QGraphicsBlurEffect()
......@@ -73,11 +81,34 @@ class MainWin(QtWidgets.QMainWindow):
self.modules[modIdx].other(**msg)
def _loadSettings(self):
from Babyfut.core.settings import Settings
if Settings['ui.fullscreen']:
self.showFullScreen()
QApplication.setOverrideCursor(Qt.BlankCursor);
else:
self.showNormal()
QApplication.setOverrideCursor(Qt.ArrowCursor);
self._retranslateUI()
def _retranslateUI(self):
app = QApplication.instance()
oldlang = self.lang
newlang = Settings['ui.language']
if newlang==oldlang:
pass # Nothing to do
elif newlang!=MainWin.DEFAULT_LANG:
self.translator = QTranslator()
if self.translator.load("babyfut_{}".format(newlang), MainWin.TR_PATH):
logging.info('Installing \'{}\''.format(newlang))
app.installTranslator(self.translator)
else:
logging.warn('Could not open translation file for \'{}\' in path "{}"'.format(newlang, MainWin.TR_PATH))
elif newlang==MainWin.DEFAULT_LANG:
logging.info('Installing language \'{}\''.format(newlang))
app.removeTranslator(self.translator)
self.translator = None
self.lang = newlang
Markdown is supported
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