hello, world
This commit is contained in:
parent
8188606c45
commit
2c85ef3010
6 changed files with 57 additions and 0 deletions
18
gfd/i18n/__init__.py
Normal file
18
gfd/i18n/__init__.py
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
import importlib
|
||||||
|
|
||||||
|
class Translator:
|
||||||
|
def __init__(self, lang="en"):
|
||||||
|
self.translations = {}
|
||||||
|
self.load(lang)
|
||||||
|
|
||||||
|
def load(self, lang):
|
||||||
|
try:
|
||||||
|
mod = importlib.import_module(f"gfd.i18n.{lang}")
|
||||||
|
self.translations = getattr(mod, "translations", {})
|
||||||
|
except ModuleNotFoundError:
|
||||||
|
# fallback to Spanish
|
||||||
|
mod = importlib.import_module("gfd.i18n.es")
|
||||||
|
self.translations = getattr(mod, "translations", {})
|
||||||
|
|
||||||
|
def __call__(self, key):
|
||||||
|
return self.translations.get(key, key)
|
||||||
4
gfd/i18n/en.py
Normal file
4
gfd/i18n/en.py
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
translations = {
|
||||||
|
"hello_world": "Hello, World!",
|
||||||
|
"window_title": "Digital Signature Manager",
|
||||||
|
}
|
||||||
4
gfd/i18n/es.py
Normal file
4
gfd/i18n/es.py
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
translations = {
|
||||||
|
"hello_world": "¡Hola, Mundo!",
|
||||||
|
"window_title": "Gestor de Firma Digital",
|
||||||
|
}
|
||||||
23
gfd/ui.py
Normal file
23
gfd/ui.py
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
from PySide6 import QtWidgets, QtCore
|
||||||
|
import gfd.i18n as i18n
|
||||||
|
|
||||||
|
class GFDWidget(QtWidgets.QWidget):
|
||||||
|
def __init__(self, tr):
|
||||||
|
super().__init__()
|
||||||
|
self.tr = tr
|
||||||
|
self.setWindowTitle(self.tr("window_title"))
|
||||||
|
self.resize(300, 100)
|
||||||
|
|
||||||
|
label = QtWidgets.QLabel(self.tr("hello_world"), alignment=QtCore.Qt.AlignCenter)
|
||||||
|
lay = QtWidgets.QVBoxLayout(self)
|
||||||
|
lay.addWidget(label)
|
||||||
|
|
||||||
|
def run(lang="es"):
|
||||||
|
import sys
|
||||||
|
app = QtWidgets.QApplication(sys.argv)
|
||||||
|
|
||||||
|
tr = i18n.Translator(lang)
|
||||||
|
w = GFDWidget(tr)
|
||||||
|
w.show()
|
||||||
|
|
||||||
|
sys.exit(app.exec())
|
||||||
4
main.py
Normal file
4
main.py
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
import gfd.ui as w
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
w.run("es")
|
||||||
4
requirements.txt
Normal file
4
requirements.txt
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
PySide6==6.9.2
|
||||||
|
PySide6_Addons==6.9.2
|
||||||
|
PySide6_Essentials==6.9.2
|
||||||
|
shiboken6==6.9.2
|
||||||
Loading…
Reference in a new issue