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

Auto-translating software

parent 9ab100f3
...@@ -11,7 +11,7 @@ import sys ...@@ -11,7 +11,7 @@ import sys
import logging import logging
from os.path import dirname, abspath, join from os.path import dirname, abspath, join
from PyQt5 import QtWidgets, QtCore from PyQt5 import QtCore
from PyQt5.QtWidgets import QMainWindow, QApplication from PyQt5.QtWidgets import QMainWindow, QApplication
def getContent(path): def getContent(path):
...@@ -28,11 +28,10 @@ def getMainWin(): ...@@ -28,11 +28,10 @@ def getMainWin():
return None return None
if __name__=='__main__': if __name__=='__main__':
print(__package__) __package__ = 'Babyfut'
from Babyfut.ui.mainwin import MainWin from Babyfut.ui.mainwin import MainWin
from Babyfut.modules import GameModule from Babyfut.modules import GameModule
from Babyfut.core.player import Side from Babyfut.core.player import Side
from Babyfut.core.settings import Settings
from Babyfut.core.input import GPIOThread from Babyfut.core.input import GPIOThread
from Babyfut.core.database import Database from Babyfut.core.database import Database
from Babyfut.core.replay import Replay as ReplayThread from Babyfut.core.replay import Replay as ReplayThread
...@@ -41,12 +40,7 @@ if __name__=='__main__': ...@@ -41,12 +40,7 @@ if __name__=='__main__':
#logging.basicConfig(filename='babyfoot.log', level=logging.DEBUG) #logging.basicConfig(filename='babyfoot.log', level=logging.DEBUG)
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)
app = QtWidgets.QApplication(sys.argv) app = QApplication(sys.argv)
lang = Settings['ui.language']
qtTranslator = QtCore.QTranslator()
if lang!='en' and qtTranslator.load("translations/babyfut_{}.qm".format(lang)):
app.installTranslator(qtTranslator)
myapp = MainWin() myapp = MainWin()
if ReplayThread.isCamAvailable(): if ReplayThread.isCamAvailable():
......
...@@ -15,11 +15,11 @@ class Module(QWidget): ...@@ -15,11 +15,11 @@ class Module(QWidget):
self.mainwin = parent self.mainwin = parent
self.ui = widget self.ui = widget
self.ui.setupUi(self) self.ui.setupUi(self)
def switchModule(self, new_type): def switchModule(self, new_type):
curmod_idx = self.mainwin.findMod(type(self)) curmod_idx = self.mainwin.findMod(type(self))
newmod_idx = self.mainwin.findMod(new_type) newmod_idx = self.mainwin.findMod(new_type)
if curmod_idx<0: if curmod_idx<0:
logging.error('Unknown panel {}'.format(type(self))) logging.error('Unknown panel {}'.format(type(self)))
elif newmod_idx<0: elif newmod_idx<0:
...@@ -28,26 +28,27 @@ class Module(QWidget): ...@@ -28,26 +28,27 @@ class Module(QWidget):
# Unfocus the current module # Unfocus the current module
if QApplication.focusWidget() != None: if QApplication.focusWidget() != None:
QApplication.focusWidget().clearFocus() QApplication.focusWidget().clearFocus()
# Swap modules by unloading, changing the ui then loading # Swap modules by unloading, changing the ui then loading
self.mainwin.modules[curmod_idx].unload() self.mainwin.modules[curmod_idx].unload()
self.mainwin.ui.panels.setCurrentIndex(newmod_idx) self.mainwin.ui.panels.setCurrentIndex(newmod_idx)
self.mainwin.ui.panels.setFocusProxy(self.mainwin.modules[newmod_idx]) self.mainwin.ui.panels.setFocusProxy(self.mainwin.modules[newmod_idx])
self.mainwin.modules[newmod_idx].setFocus() self.mainwin.modules[newmod_idx].setFocus()
# Select first element of the Module # Select first element of the Module
self.mainwin.modules[newmod_idx].focusNextChild() self.mainwin.modules[newmod_idx].focusNextChild()
self.mainwin.modules[newmod_idx].focusPreviousChild() self.mainwin.modules[newmod_idx].focusPreviousChild()
self.mainwin.modules[newmod_idx].ui.retranslateUi(self.mainwin)
self.mainwin.modules[newmod_idx].load() self.mainwin.modules[newmod_idx].load()
def send(self, to, **kwargs): def send(self, to, **kwargs):
mod_idx = self.mainwin.findMod(to) mod_idx = self.mainwin.findMod(to)
if mod_idx<0: if mod_idx<0:
logging.error('Unknown panel {}'.format(to)) logging.error('Unknown panel {}'.format(to))
else: else:
self.mainwin.modules[mod_idx].other(**kwargs) self.mainwin.modules[mod_idx].other(**kwargs)
def load(self): def load(self):
logging.warning('Unimplemented method "load" for {}'.format(self.__class__)) logging.warning('Unimplemented method "load" for {}'.format(self.__class__))
......
...@@ -245,6 +245,21 @@ ...@@ -245,6 +245,21 @@
<source>Privacy</source> <source>Privacy</source>
<translation>Vie Privée</translation> <translation>Vie Privée</translation>
</message> </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"> <message encoding="UTF-8">
<location filename="../ui/options_ui.py" line="229"/> <location filename="../ui/options_ui.py" line="229"/>
<source>Français</source> <source>Français</source>
...@@ -285,7 +300,7 @@ ...@@ -285,7 +300,7 @@
<byte value="x9"/><byte value="x9"/><byte value="x9"/>&lt;li&gt;Your Picture (if public)&lt;/li&gt; <byte value="x9"/><byte value="x9"/><byte value="x9"/>&lt;li&gt;Your Picture (if public)&lt;/li&gt;
<byte value="x9"/><byte value="x9"/><byte value="x9"/>&lt;li&gt;...&lt;/li&gt; <byte value="x9"/><byte value="x9"/><byte value="x9"/>&lt;li&gt;...&lt;/li&gt;
<byte value="x9"/><byte value="x9"/>&lt;/ul&gt; <byte value="x9"/><byte value="x9"/>&lt;/ul&gt;
<byte value="x9"/><byte value="x9"/>&lt;/p&gt; <byte value="x9"/><byte value="x9"/>&lt;/p&gt;
<byte value="x9"/><byte value="x9"/>&lt;p&gt; <byte value="x9"/><byte value="x9"/>&lt;p&gt;
<byte value="x9"/><byte value="x9"/>That way players can keep track of their score and compare it with others. <byte value="x9"/><byte value="x9"/>That way players can keep track of their score and compare it with others.
......
...@@ -5,20 +5,28 @@ ...@@ -5,20 +5,28 @@
""" """
import os import os
from os.path import join, dirname, abspath
import logging
OnRasp = os.uname()[1] == 'raspberrypi' OnRasp = os.uname()[1] == 'raspberrypi'
from PyQt5 import QtWidgets from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QGraphicsBlurEffect, QApplication 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 import modules
from Babyfut.ui.main_ui import Ui_MainWindow
from Babyfut.core.settings import Settings
class MainWin(QtWidgets.QMainWindow): class MainWin(QtWidgets.QMainWindow):
DEFAULT_LANG = 'en'
TR_PATH = join(dirname(dirname(abspath(__file__))), 'translations/')
def __init__(self, parent=None): def __init__(self, parent=None):
QtWidgets.QWidget.__init__(self, parent) QtWidgets.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow() self.ui = Ui_MainWindow()
self.ui.setupUi(self) self.ui.setupUi(self)
self.lang = MainWin.DEFAULT_LANG
self._retranslateUI()
#Background blur #Background blur
bgBlur = QGraphicsBlurEffect() bgBlur = QGraphicsBlurEffect()
...@@ -73,11 +81,34 @@ class MainWin(QtWidgets.QMainWindow): ...@@ -73,11 +81,34 @@ class MainWin(QtWidgets.QMainWindow):
self.modules[modIdx].other(**msg) self.modules[modIdx].other(**msg)
def _loadSettings(self): def _loadSettings(self):
from Babyfut.core.settings import Settings
if Settings['ui.fullscreen']: if Settings['ui.fullscreen']:
self.showFullScreen() self.showFullScreen()
QApplication.setOverrideCursor(Qt.BlankCursor); QApplication.setOverrideCursor(Qt.BlankCursor);
else: else:
self.showNormal() self.showNormal()
QApplication.setOverrideCursor(Qt.ArrowCursor); 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