diff --git a/main.pyw b/main.pyw index d4349b2..d429815 100644 --- a/main.pyw +++ b/main.pyw @@ -13,17 +13,17 @@ from source.definition import * class ClassApp(): from source.__init__ import __init__ - from source.translate import translate + from source.translate import translate, change_language, get_language from source.Progress import Progress from source.check_update import check_update from source.StateButton import StateButton from source.create_lecode_config import create_lecode_config from source.patch_file import patch_file from source.install_mod import install_mod + from source.restart import restart -# TODO: Langue # TODO: Wiki Github # TODO: Autogénération des bmg App = ClassApp() -mainloop() \ No newline at end of file +App.root.mainloop() \ No newline at end of file diff --git a/source/__init__.py b/source/__init__.py index 741c41e..81042df 100644 --- a/source/__init__.py +++ b/source/__init__.py @@ -8,21 +8,31 @@ from .definition import * from .check_update import check_update from .translate import translate - def __init__(self): - self.language = "fr" + self.language = self.get_language() self.root = Tk() self.root.title(self.translate("MKWFaraphel Installateur")) self.root.resizable(False, False) self.root.iconbitmap(bitmap="./icon.ico") - self.frame_game_path = LabelFrame(self.root, text=self.translate("Jeu original")) - self.frame_game_path.grid(row=1, column=1) - self.check_update() self.path_mkwf = None + self.frame_language = Frame(self.root) + self.frame_language.grid(row=1, column=1, sticky="E") + + Label(self.frame_language, text=self.translate("Langage : ")).grid(row=1, column=1) + self.listbox_language = ttk.Combobox(self.frame_language, values=["fr", "en"], width=5) + self.listbox_language.set(self.language) + self.listbox_language.grid(row=1, column=2) + + + self.listbox_language.bind("<>", lambda x: self.change_language()) + + self.frame_game_path = LabelFrame(self.root, text=self.translate("Jeu original")) + self.frame_game_path.grid(row=2, column=1) + entry_game_path = Entry(self.frame_game_path, width=50) entry_game_path.grid(row=1, column=1, sticky="NEWS") @@ -71,7 +81,7 @@ def __init__(self): self.translate("Cette ROM est déjà moddé, " + "il est déconseillé de l'utiliser pour installer le mod")) - self.frame_action.grid(row=2, column=1, sticky="NEWS") + self.frame_action.grid(row=3, column=1, sticky="NEWS") self.Progress(show=False) t = Thread(target=func) diff --git a/source/restart.py b/source/restart.py new file mode 100644 index 0000000..f23f641 --- /dev/null +++ b/source/restart.py @@ -0,0 +1,7 @@ +import sys +import os + + +def restart(self): + os.execl(sys.executable, f'"{sys.executable}"', *sys.argv) + sys.exit() \ No newline at end of file diff --git a/source/translate.py b/source/translate.py index 1b06818..78b6dbb 100644 --- a/source/translate.py +++ b/source/translate.py @@ -1,9 +1,24 @@ import json + def translate(self, text): with open("./translation.json", encoding="utf-8") as f: translation = json.load(f) if self.language in translation: _lang_trad = translation[self.language] if text in _lang_trad: return _lang_trad[text] - return text \ No newline at end of file + return text + + +def change_language(self): + with open("./translation.json", encoding="utf-8") as f: translation = json.load(f) + translation["selected"] = self.listbox_language.get() + with open("./translation.json", "w", encoding="utf-8") as f: json.dump(translation, f) + + self.restart() + + +def get_language(self): + with open("./translation.json", encoding="utf-8") as f: translation = json.load(f) + if "selected" in translation: return translation["selected"] + else: return "fr" \ No newline at end of file diff --git a/translation.json b/translation.json index 7081b9f..09d0d68 100644 --- a/translation.json +++ b/translation.json @@ -1,39 +1 @@ -{ - "en": { - "MKWFaraphel Installateur": "MKWFaraphel Installer", - "Jeu Wii": "Wii game", - "Jeu original": "Original game", - "Erreur": "Error", - "Le chemin de fichier est invalide": "The file path in invalid", - "Attention": "Warning", - "Ce dossier sera écrasé si vous installer le mod !\nÊtes-vous sûr de vouloir l'utiliser ?": "This directory will be overwritten if you install the mod !\nAre you sure you want to use it ?", - "Extraction du jeu...": "Extracting the game...", - "Le type de fichier n'est pas reconnu": "This file type is not supported", - "Cette ROM est déjà moddé, il est déconseillé de l'utiliser pour installer le mod": "This game is already modded, it is not recommended to use it to install the mod", - "Extraire le fichier": "Extract file", - "Preparer les fichiers": "Prepare files", - "Action": "Action", - "Installer le mod": "Install mod", - "Dossier": "Directory", - - "Mise à jour disponible !": "Update available !", - "Une mise à jour est disponible, souhaitez-vous l'installer ?": "An update is available, do you want to install it ?", - "Téléchargement de Updater en cours...": "Downloading the Updater...", - "fin du téléchargement, début de l'extraction...": "end of the download, extracting...", - "fin de l'extraction": "finished extracting", - "lancement de l'application...": "starting application...", - - "Modification de": "Modifying", - "Recompilation de": "Recompilating", - "Conversion en": "Converting to", - "Changement de l'ID du jeu": "editing game's ID", - "Fin": "End", - "L'installation est terminé !": "The mod has been installed !", - - "Conversion des fichiers": "Converting files", - "Conversion des images": "Converting images", - "Conversion des textes": "Converting texts", - "Conversion des courses": "Converting races", - "Configuration de LE-CODE": "Configurating LE-CODE" - } -} \ No newline at end of file +{"en": {"MKWFaraphel Installateur": "MKWFaraphel Installer", "Jeu Wii": "Wii game", "Jeu original": "Original game", "Erreur": "Error", "Le chemin de fichier est invalide": "The file path in invalid", "Attention": "Warning", "Ce dossier sera \u00e9cras\u00e9 si vous installer le mod !\n\u00cates-vous s\u00fbr de vouloir l'utiliser ?": "This directory will be overwritten if you install the mod !\nAre you sure you want to use it ?", "Extraction du jeu...": "Extracting the game...", "Le type de fichier n'est pas reconnu": "This file type is not supported", "Cette ROM est d\u00e9j\u00e0 modd\u00e9, il est d\u00e9conseill\u00e9 de l'utiliser pour installer le mod": "This game is already modded, it is not recommended to use it to install the mod", "Extraire le fichier": "Extract file", "Preparer les fichiers": "Prepare files", "Action": "Action", "Installer le mod": "Install mod", "Dossier": "Directory", "Langage : ": "Language : ", "Mise \u00e0 jour disponible !": "Update available !", "Une mise \u00e0 jour est disponible, souhaitez-vous l'installer ?": "An update is available, do you want to install it ?", "T\u00e9l\u00e9chargement de Updater en cours...": "Downloading the Updater...", "fin du t\u00e9l\u00e9chargement, d\u00e9but de l'extraction...": "end of the download, extracting...", "fin de l'extraction": "finished extracting", "lancement de l'application...": "starting application...", "Modification de": "Modifying", "Recompilation de": "Recompilating", "Conversion en": "Converting to", "Changement de l'ID du jeu": "editing game's ID", "Fin": "End", "L'installation est termin\u00e9 !": "The mod has been installed !", "Conversion des fichiers": "Converting files", "Conversion des images": "Converting images", "Conversion des textes": "Converting texts", "Conversion des courses": "Converting races", "Configuration de LE-CODE": "Configurating LE-CODE"}, "selected": "en"} \ No newline at end of file