mirror of
https://github.com/Faraphel/Atlas-Install.git
synced 2025-07-02 18:58:27 +02:00
moved translate from gui to its own class (Translator), added missing translation
This commit is contained in:
parent
e5fefd0624
commit
b29a7d0dcf
6 changed files with 146 additions and 111 deletions
|
@ -2,7 +2,8 @@ from source.CT_Config import CT_Config
|
|||
from source.Option import Option
|
||||
from source.Game import Game
|
||||
from source.Gui.Main import Main
|
||||
from source.Gui.TrackSelection import TrackSelection
|
||||
from source.Gui.TrackConfiguration import TrackConfiguration
|
||||
from source.Translation import Translator
|
||||
|
||||
|
||||
class Common:
|
||||
|
@ -13,6 +14,8 @@ class Common:
|
|||
"""
|
||||
|
||||
self.json_frame_filter = None
|
||||
self.translator = Translator(common=self)
|
||||
self.translate = self.translator.translate # shortcut for the method
|
||||
|
||||
self.option = Option().load_from_file("./option.json")
|
||||
self.ct_config = CT_Config()
|
||||
|
@ -20,5 +23,5 @@ class Common:
|
|||
|
||||
self.gui_main = Main(common=self)
|
||||
|
||||
def show_gui_track_configuration(self): TrackSelection(common=self)
|
||||
def mainloop(self): self.gui_main.mainloop()
|
||||
def show_gui_track_configuration(self): TrackConfiguration(common=self)
|
||||
def mainloop(self): self.gui_main.mainloop()
|
||||
|
|
|
@ -46,7 +46,7 @@ class Game:
|
|||
shutil.rmtree(self.path)
|
||||
self.path = path_game_format
|
||||
|
||||
self.common.gui_main.progress(statut=self.common.gui_main.translate("Changing game's ID"), add=1)
|
||||
self.common.gui_main.progress(statut=self.common.translate("Changing game's ID"), add=1)
|
||||
wit.edit(
|
||||
file=self.path,
|
||||
region_ID=self.region_ID,
|
||||
|
@ -129,7 +129,7 @@ class Game:
|
|||
fs = json.load(f)
|
||||
|
||||
extracted_file = []
|
||||
self.common.gui_main.progress(show=True, indeter=False, statut=self.common.gui_main.translate("Modifying subfile..."), add=1)
|
||||
self.common.gui_main.progress(show=True, indeter=False, statut=self.common.translate("Modifying subfile..."), add=1)
|
||||
|
||||
def replace_file(path, file, subpath="/") -> None:
|
||||
"""
|
||||
|
@ -138,7 +138,7 @@ class Game:
|
|||
:param file: file to replace
|
||||
:param subpath: directory between .szs file and file inside to replace
|
||||
"""
|
||||
self.common.gui_main.progress(statut=self.common.gui_main.translate("Editing", "\n", get_nodir(path)), add=1)
|
||||
self.common.gui_main.progress(statut=self.common.translate("Editing", "\n", get_nodir(path)), add=1)
|
||||
extension = get_extension(path)
|
||||
|
||||
source_file = f"{self.common.ct_config.pack_path}/file/{file}"
|
||||
|
@ -170,7 +170,7 @@ class Game:
|
|||
for ffp in fs[fp][nf]: replace_file(path=f, subpath=nf, file=ffp)
|
||||
|
||||
for file in extracted_file:
|
||||
self.common.gui_main.progress(statut=self.common.gui_main.translate("Recompilating", "\n", get_nodir(file)), add=1)
|
||||
self.common.gui_main.progress(statut=self.common.translate("Recompilating", "\n", get_nodir(file)), add=1)
|
||||
szs.create(file=file)
|
||||
shutil.rmtree(file + ".d", ignore_errors=True)
|
||||
|
||||
|
@ -178,7 +178,7 @@ class Game:
|
|||
"""
|
||||
copy MyStuff directory into the game *before* patching the game
|
||||
"""
|
||||
self.common.gui_main.progress(show=True, indeter=False, statut=self.common.gui_main.translate("Copying MyStuff..."), add=1)
|
||||
self.common.gui_main.progress(show=True, indeter=False, statut=self.common.translate("Copying MyStuff..."), add=1)
|
||||
|
||||
mystuff_folder = self.common.gui_main.stringvar_mystuff_folder.get()
|
||||
if mystuff_folder and mystuff_folder != "None":
|
||||
|
@ -206,7 +206,7 @@ class Game:
|
|||
"""
|
||||
patch the main.dol file to allow the addition of LECODE.bin file
|
||||
"""
|
||||
self.common.gui_main.progress(statut=self.common.gui_main.translate("Patch main.dol"), add=1)
|
||||
self.common.gui_main.progress(statut=self.common.translate("Patch main.dol"), add=1)
|
||||
|
||||
region_id = self.common.ct_config.region if self.common.gui_main.is_using_official_config() else self.common.ct_config.cheat_region
|
||||
wstrt.patch(path=self.path, region_id=region_id)
|
||||
|
@ -215,7 +215,7 @@ class Game:
|
|||
"""
|
||||
configure and add the LECODE.bin file to the mod
|
||||
"""
|
||||
self.common.gui_main.progress(statut=self.common.gui_main.translate("Patch lecode.bin"), add=1)
|
||||
self.common.gui_main.progress(statut=self.common.translate("Patch lecode.bin"), add=1)
|
||||
|
||||
lpar_path = self.common.ct_config.file_process["placement"].get("lpar_dir")
|
||||
if not lpar_path: f""
|
||||
|
@ -243,7 +243,7 @@ class Game:
|
|||
convert the rom to the selected game format
|
||||
"""
|
||||
output_format = self.common.gui_main.stringvar_game_format.get()
|
||||
self.common.gui_main.progress(statut=self.common.gui_main.translate("Converting to", " ", output_format), add=1)
|
||||
self.common.gui_main.progress(statut=self.common.translate("Converting to", " ", output_format), add=1)
|
||||
self.convert_to(output_format)
|
||||
|
||||
def install_mod(self) -> None:
|
||||
|
@ -254,14 +254,14 @@ class Game:
|
|||
max_step = 5 + self.count_patch_subfile_operation()
|
||||
# PATCH main.dol and PATCH lecode.bin, converting, changing ID, copying MyStuff Folder
|
||||
|
||||
self.common.gui_main.progress(statut=self.common.gui_main.translate("Installing mod..."), max=max_step, step=0)
|
||||
self.common.gui_main.progress(statut=self.common.translate("Installing mod..."), max=max_step, step=0)
|
||||
self.install_copy_mystuff()
|
||||
self.install_patch_subfile()
|
||||
self.install_patch_maindol()
|
||||
self.install_patch_lecode()
|
||||
self.install_convert_rom()
|
||||
|
||||
messagebox.showinfo(self.common.gui_main.translate("End"), self.common.gui_main.translate("The mod have been installed !"))
|
||||
messagebox.showinfo(self.common.translate("End"), self.common.translate("The mod have been installed !"))
|
||||
|
||||
except Exception as e:
|
||||
self.common.gui_main.log_error()
|
||||
|
@ -337,7 +337,7 @@ class Game:
|
|||
}
|
||||
|
||||
bmglang = gamefile[-len("E.txt"):-len(".txt")] # Langue du fichier
|
||||
self.common.gui_main.progress(statut=self.common.gui_main.translate("Patching text", " ", bmglang), add=1)
|
||||
self.common.gui_main.progress(statut=self.common.translate("Patching text", " ", bmglang), add=1)
|
||||
|
||||
szs.extract(file=gamefile)
|
||||
|
||||
|
@ -429,9 +429,9 @@ class Game:
|
|||
3 + \
|
||||
len("EGFIS")
|
||||
|
||||
self.common.gui_main.progress(show=True, indeter=False, statut=self.common.gui_main.translate("Converting files"),
|
||||
self.common.gui_main.progress(show=True, indeter=False, statut=self.common.translate("Converting files"),
|
||||
max=max_step, step=0)
|
||||
self.common.gui_main.progress(statut=self.common.gui_main.translate("Configurating LE-CODE"), add=1)
|
||||
self.common.gui_main.progress(statut=self.common.translate("Configurating LE-CODE"), add=1)
|
||||
self.common.ct_config.create_ctfile()
|
||||
|
||||
self.generate_cticons()
|
||||
|
@ -465,7 +465,7 @@ class Game:
|
|||
|
||||
for i, (file, data) in enumerate(self.common.ct_config.file_process["img_encode"].items()):
|
||||
self.common.gui_main.progress(
|
||||
statut=self.common.gui_main.translate("Converting images") + f"\n({i + 1}/{image_amount}) {file}",
|
||||
statut=self.common.translate("Converting images") + f"\n({i + 1}/{image_amount}) {file}",
|
||||
add=1
|
||||
)
|
||||
|
||||
|
@ -575,7 +575,7 @@ class Game:
|
|||
thread_list[track.sha1] = Thread(target=add_process, args=[track])
|
||||
thread_list[track.sha1].setDaemon(True)
|
||||
thread_list[track.sha1].start()
|
||||
self.common.gui_main.progress(statut=self.common.gui_main.translate("Converting tracks", f"\n({i + 1}/{total_track})\n",
|
||||
self.common.gui_main.progress(statut=self.common.translate("Converting tracks", f"\n({i + 1}/{total_track})\n",
|
||||
"\n".join(thread_list.keys())), add=1)
|
||||
break
|
||||
clean_process()
|
||||
|
|
|
@ -12,10 +12,6 @@ from source.Error import *
|
|||
from source.definition import *
|
||||
|
||||
|
||||
with open("./translation.json", encoding="utf-8") as f:
|
||||
translation_dict = json.load(f)
|
||||
|
||||
|
||||
class Main:
|
||||
def __init__(self, common) -> None:
|
||||
"""
|
||||
|
@ -31,8 +27,8 @@ class Main:
|
|||
self.available_packs = self.get_available_packs()
|
||||
if not self.available_packs:
|
||||
messagebox.showerror(
|
||||
self.translate("Error"),
|
||||
self.translate("There is no pack in the ./Pack/ directory.")
|
||||
self.common.translate("Error"),
|
||||
self.common.translate("There is no pack in the ./Pack/ directory.")
|
||||
)
|
||||
self.quit()
|
||||
|
||||
|
@ -44,7 +40,7 @@ class Main:
|
|||
self.boolvar_dont_check_for_update = BooleanVar(value=self.common.option.dont_check_for_update)
|
||||
self.intvar_process_track = IntVar(value=self.common.option.process_track)
|
||||
|
||||
self.root.title(self.translate("MKWFaraphel Installer"))
|
||||
self.root.title(self.common.translate("MKWFaraphel Installer"))
|
||||
|
||||
self.boolvar_use_debug_mode = BooleanVar(value=False)
|
||||
self.boolvar_force_unofficial_mode = BooleanVar(value=False)
|
||||
|
@ -55,7 +51,7 @@ class Main:
|
|||
|
||||
# GUI
|
||||
# Mod selector
|
||||
self.frame_ctconfig = LabelFrame(self.root, text=self.translate("Mod"))
|
||||
self.frame_ctconfig = LabelFrame(self.root, text=self.common.translate("Mod"))
|
||||
self.frame_ctconfig.grid(row=1, column=1, sticky="NWS")
|
||||
|
||||
self.combobox_ctconfig_path = ttk.Combobox(
|
||||
|
@ -69,7 +65,7 @@ class Main:
|
|||
self.reload_ctconfig()
|
||||
|
||||
# Jeu
|
||||
self.frame_game_path = LabelFrame(self.root, text=self.translate("Original game"))
|
||||
self.frame_game_path = LabelFrame(self.root, text=self.common.translate("Original game"))
|
||||
self.frame_game_path.grid(row=2, column=1)
|
||||
|
||||
entry_game_path = Entry(self.frame_game_path, width=50)
|
||||
|
@ -77,7 +73,7 @@ class Main:
|
|||
|
||||
def select_path():
|
||||
path = filedialog.askopenfilename(
|
||||
filetypes=((self.translate("Wii game"), r"*.iso *.wbfs main.dol *.wia *.ciso"),)
|
||||
filetypes=((self.common.translate("Wii game"), r"*.iso *.wbfs main.dol *.wia *.ciso"),)
|
||||
)
|
||||
if os.path.exists(path):
|
||||
entry_game_path.delete(0, END)
|
||||
|
@ -96,17 +92,17 @@ class Main:
|
|||
if not os.path.exists(game_path): raise InvalidGamePath
|
||||
|
||||
self.common.game.set_path(game_path)
|
||||
self.progress(show=True, indeter=True, statut=self.translate("Extracting the game..."))
|
||||
self.progress(show=True, indeter=True, statut=self.common.translate("Extracting the game..."))
|
||||
self.common.game.extract()
|
||||
|
||||
except RomAlreadyPatched:
|
||||
messagebox.showerror(self.translate("Error"), self.translate("This game is already modded"))
|
||||
messagebox.showerror(self.common.translate("Error"), self.common.translate("This game is already modded"))
|
||||
raise RomAlreadyPatched
|
||||
except InvalidGamePath:
|
||||
messagebox.showerror(self.translate("Error"), self.translate("The file path in invalid"))
|
||||
messagebox.showerror(self.common.translate("Error"), self.common.translate("The file path in invalid"))
|
||||
raise InvalidGamePath
|
||||
except InvalidFormat:
|
||||
messagebox.showerror(self.translate("Error"), self.translate("This game's format is invalid"))
|
||||
messagebox.showerror(self.common.translate("Error"), self.common.translate("This game's format is invalid"))
|
||||
raise InvalidFormat
|
||||
except Exception as e:
|
||||
self.log_error()
|
||||
|
@ -122,7 +118,7 @@ class Main:
|
|||
|
||||
self.button_do_everything = Button(
|
||||
self.frame_game_path_action,
|
||||
text=self.translate("Install mod"),
|
||||
text=self.common.translate("Install mod"),
|
||||
relief=RIDGE,
|
||||
command=do_everything
|
||||
)
|
||||
|
@ -138,7 +134,7 @@ class Main:
|
|||
|
||||
# LANGUAGE MENU
|
||||
self.menu_language = Menu(self.menu_bar, tearoff=0)
|
||||
self.menu_bar.add_cascade(label=self.translate("Language"), menu=self.menu_language)
|
||||
self.menu_bar.add_cascade(label=self.common.translate("Language"), menu=self.menu_language)
|
||||
self.menu_language.add_radiobutton(
|
||||
label="Français",
|
||||
variable=self.stringvar_language,
|
||||
|
@ -154,9 +150,9 @@ class Main:
|
|||
|
||||
# OUTPUT FORMAT MENU
|
||||
self.menu_format = Menu(self.menu_bar, tearoff=0)
|
||||
self.menu_bar.add_cascade(label=self.translate("Format"), menu=self.menu_format)
|
||||
self.menu_bar.add_cascade(label=self.common.translate("Format"), menu=self.menu_format)
|
||||
self.menu_format.add_radiobutton(
|
||||
label=self.translate("FST (Directory)"),
|
||||
label=self.common.translate("FST (Directory)"),
|
||||
variable=self.stringvar_game_format,
|
||||
value="FST", command=lambda:
|
||||
self.common.option.edit("format", "FST")
|
||||
|
@ -183,9 +179,9 @@ class Main:
|
|||
# ADVANCED MENU
|
||||
## INSTALLER PARAMETER
|
||||
self.menu_advanced = Menu(self.menu_bar, tearoff=0)
|
||||
self.menu_bar.add_cascade(label=self.translate("Advanced"), menu=self.menu_advanced)
|
||||
self.menu_bar.add_cascade(label=self.common.translate("Advanced"), menu=self.menu_advanced)
|
||||
self.menu_advanced.add_checkbutton(
|
||||
label=self.translate("Don't check for update"),
|
||||
label=self.common.translate("Don't check for update"),
|
||||
variable=self.boolvar_dont_check_for_update,
|
||||
command=lambda: self.common.option.edit(
|
||||
"dont_check_for_update",
|
||||
|
@ -193,19 +189,19 @@ class Main:
|
|||
)
|
||||
)
|
||||
self.menu_advanced.add_checkbutton(
|
||||
label=self.translate("Force \"unofficial\" mode"),
|
||||
label=self.common.translate("Force \"unofficial\" mode"),
|
||||
variable=self.boolvar_force_unofficial_mode
|
||||
)
|
||||
|
||||
self.menu_conv_process = Menu(self.menu_advanced, tearoff=0)
|
||||
self.menu_advanced.add_cascade(
|
||||
label=self.translate("Number of track conversion process"),
|
||||
label=self.common.translate("Number of track conversion process"),
|
||||
menu=self.menu_conv_process
|
||||
)
|
||||
|
||||
for process_number in range(1, 8+1):
|
||||
self.menu_conv_process.add_radiobutton(
|
||||
label=self.translate(f"{process_number} ", "process"),
|
||||
label=self.common.translate(f"{process_number} ", "process"),
|
||||
variable=self.intvar_process_track, value=process_number,
|
||||
command=lambda p=process_number: self.common.option.edit("process_track", p)
|
||||
)
|
||||
|
@ -214,17 +210,17 @@ class Main:
|
|||
self.menu_advanced.add_separator()
|
||||
|
||||
self.menu_advanced.add_command(
|
||||
label=self.translate("Change track configuration"),
|
||||
label=self.common.translate("Change track configuration"),
|
||||
command=self.common.show_gui_track_configuration
|
||||
)
|
||||
|
||||
self.menu_advanced.add_checkbutton(
|
||||
label=self.translate("Use debug mode"),
|
||||
label=self.common.translate("Use debug mode"),
|
||||
variable=self.boolvar_use_debug_mode
|
||||
)
|
||||
|
||||
self.menu_mystuff = Menu(self.menu_advanced, tearoff=0)
|
||||
self.menu_advanced.add_cascade(label=self.translate("MyStuff"), menu=self.menu_mystuff)
|
||||
self.menu_advanced.add_cascade(label=self.common.translate("MyStuff"), menu=self.menu_mystuff)
|
||||
|
||||
def add_menu_mystuff_command(stringvar: StringVar, label: str):
|
||||
self.menu_mystuff.add_command()
|
||||
|
@ -236,7 +232,7 @@ class Main:
|
|||
mystuff_dir = filedialog.askdirectory()
|
||||
if mystuff_dir: stringvar.set(mystuff_dir)
|
||||
|
||||
self.menu_mystuff.entryconfig(index, label=self.translate(
|
||||
self.menu_mystuff.entryconfig(index, label=self.common.translate(
|
||||
"Apply", " ", label, f" ({stringvar.get()!r} ", "selected", ")")
|
||||
)
|
||||
|
||||
|
@ -249,7 +245,7 @@ class Main:
|
|||
|
||||
# HELP MENU
|
||||
self.menu_help = Menu(self.menu_bar, tearoff=0)
|
||||
self.menu_bar.add_cascade(label=self.translate("Help"), menu=self.menu_help)
|
||||
self.menu_bar.add_cascade(label=self.common.translate("Help"), menu=self.menu_help)
|
||||
self.menu_help.add_command(label="Github Wiki", command=lambda: webbrowser.open(GITHUB_HELP_PAGE_URL))
|
||||
self.menu_help.add_command(label="Discord", command=lambda: webbrowser.open(DISCORD_URL))
|
||||
|
||||
|
@ -283,33 +279,33 @@ class Main:
|
|||
|
||||
if github_version > local_version: # if github version is newer than local version
|
||||
if messagebox.askyesno(
|
||||
self.translate("Update available !"),
|
||||
self.translate("An update is available, do you want to install it ?",
|
||||
self.common.translate("Update available !"),
|
||||
self.common.translate("An update is available, do you want to install it ?",
|
||||
f"\n\nVersion : {local_version} -> {github_version}\n"
|
||||
f"Changelog :\n{github_version_data['changelog']}")):
|
||||
|
||||
if not (os.path.exists("./Updater/Updater.exe")):
|
||||
dl = requests.get(github_version_data["updater_bin"], allow_redirects=True)
|
||||
with open("./download.zip", "wb") as file:
|
||||
print(self.translate("Downloading the Updater..."))
|
||||
print(self.common.translate("Downloading the Updater..."))
|
||||
file.write(dl.content)
|
||||
print(self.translate("end of the download, extracting..."))
|
||||
print(self.common.translate("end of the download, extracting..."))
|
||||
|
||||
with zipfile.ZipFile("./download.zip") as file:
|
||||
file.extractall("./Updater/")
|
||||
print(self.translate("finished extracting"))
|
||||
print(self.common.translate("finished extracting"))
|
||||
|
||||
os.remove("./download.zip")
|
||||
|
||||
print(self.translate("starting application..."))
|
||||
print(self.common.translate("starting application..."))
|
||||
os.startfile(os.path.realpath("./Updater/Updater.exe"))
|
||||
|
||||
elif local_version > github_version:
|
||||
self.is_dev_version = True
|
||||
|
||||
except requests.ConnectionError:
|
||||
messagebox.showwarning(self.translate("Warning"),
|
||||
self.translate("Can't connect to internet. Download will be disabled."))
|
||||
messagebox.showwarning(self.common.translate("Warning"),
|
||||
self.common.translate("Can't connect to internet. Download will be disabled."))
|
||||
self.common.option.disable_download = True
|
||||
|
||||
except:
|
||||
|
@ -330,8 +326,8 @@ class Main:
|
|||
f"{error}\n"
|
||||
)
|
||||
messagebox.showerror(
|
||||
self.translate("Error"),
|
||||
self.translate("An error occured", " :", "\n", error, "\n\n")
|
||||
self.common.translate("Error"),
|
||||
self.common.translate("An error occured", " :", "\n", error, "\n\n")
|
||||
)
|
||||
|
||||
def progress(self, show: bool = None, indeter: bool = None, step: int = None,
|
||||
|
@ -381,25 +377,6 @@ class Main:
|
|||
if enable: widget.config(state=NORMAL)
|
||||
else: widget.config(state=DISABLED)
|
||||
|
||||
def translate(self, *texts, gamelang: str = None) -> str:
|
||||
"""
|
||||
translate text into an another language in translation.json file
|
||||
:param texts: all text to convert
|
||||
:param gamelang: force a destination language to convert track
|
||||
:return: translated text
|
||||
"""
|
||||
lang = gamelang_to_lang.get(gamelang, self.common.option.language)
|
||||
if lang not in translation_dict: return "".join(texts) # if no translation language is found
|
||||
|
||||
_lang_trad = translation_dict[lang]
|
||||
translated_text = ""
|
||||
for text in texts:
|
||||
if text in _lang_trad: translated_text += _lang_trad[text]
|
||||
else:
|
||||
print(f"No translation found for ({lang}) {text}")
|
||||
translated_text += text
|
||||
return translated_text
|
||||
|
||||
def is_using_official_config(self) -> bool:
|
||||
"""
|
||||
:return: True if the parameter is the official one, False if it is customized
|
||||
|
|
|
@ -25,28 +25,28 @@ class Orderbox(Listbox):
|
|||
self.selection_set(index - delta_start + delta_end)
|
||||
|
||||
|
||||
class TrackSelection:
|
||||
class TrackConfiguration:
|
||||
def __init__(self, common):
|
||||
self.common = common
|
||||
|
||||
self.root = Toplevel(self.common.gui_main.root)
|
||||
self.root.title("Track selection")
|
||||
self.root.title(self.common.translate("Track configuration"))
|
||||
self.root.iconbitmap("./icon.ico")
|
||||
self.root.resizable(False, False)
|
||||
self.root.grab_set()
|
||||
|
||||
self.text_is_equal_to = "is equal to"
|
||||
self.text_is_in = "is in"
|
||||
self.text_is_between = "is between"
|
||||
self.text_contains = "contains"
|
||||
self.text_is_equal_to = self.common.translate("is equal to")
|
||||
self.text_is_in = self.common.translate("is in")
|
||||
self.text_is_between = self.common.translate("is between")
|
||||
self.text_contains = self.common.translate("contains")
|
||||
|
||||
self.text_and = "and"
|
||||
self.text_nand = "nand"
|
||||
self.text_or = "or"
|
||||
self.text_nor = "nor"
|
||||
self.text_xor = "xor"
|
||||
self.text_xnor = "xnor"
|
||||
self.condition_link_end = "end"
|
||||
self.text_and = self.common.translate("and")
|
||||
self.text_nand = self.common.translate("nand")
|
||||
self.text_or = self.common.translate("or")
|
||||
self.text_nor = self.common.translate("nor")
|
||||
self.text_xor = self.common.translate("xor")
|
||||
self.text_xnor = self.common.translate("xnor")
|
||||
self.condition_link_end = self.common.translate("end")
|
||||
|
||||
self.condition_links = {
|
||||
self.text_and: lambda a, b: lambda track: a(track) and b(track),
|
||||
|
@ -65,10 +65,10 @@ class TrackSelection:
|
|||
|
||||
return change_enable_track_filter
|
||||
|
||||
self.track_sort = LabelFrame(self.root, text="Sort Track")
|
||||
self.track_sort = LabelFrame(self.root, text=self.common.translate("Sort Track"))
|
||||
self.track_sort.grid(row=1, column=1, sticky="NEWS")
|
||||
|
||||
Label(self.track_sort, text="Sort track by : ").grid(row=1, column=1)
|
||||
Label(self.track_sort, text=self.common.translate("Sort track by"," : ")).grid(row=1, column=1)
|
||||
self.combobox_track_sort = ttk.Combobox(
|
||||
self.track_sort,
|
||||
values=list(self.common.ct_config.get_all_track_possibilities())
|
||||
|
@ -76,14 +76,14 @@ class TrackSelection:
|
|||
self.combobox_track_sort.grid(row=1, column=2, sticky="NEWS")
|
||||
self.combobox_track_sort.insert(END, self.common.ct_config.sort_track_attr)
|
||||
|
||||
self.track_filter = LabelFrame(self.root, text="Filter Track")
|
||||
self.track_filter = LabelFrame(self.root, text=self.common.translate("Filter Track"))
|
||||
self.track_filter.grid(row=2, column=1, sticky="NEWS")
|
||||
|
||||
self.variable_enable_track_filter = BooleanVar(value=False)
|
||||
self.frames_track_filter = []
|
||||
self.checkbutton_track_filter = ttk.Checkbutton(
|
||||
self.track_filter,
|
||||
text="Enable track filter",
|
||||
text=self.common.translate("Enable track filter"),
|
||||
variable=self.variable_enable_track_filter,
|
||||
command=get_change_enable_track_filter_func(
|
||||
self.track_filter,
|
||||
|
@ -94,7 +94,7 @@ class TrackSelection:
|
|||
self.checkbutton_track_filter.grid(row=1, column=1)
|
||||
Label(
|
||||
self.track_filter,
|
||||
text="Warning : only unordered tracks are affected by this option.",
|
||||
text=self.common.translate("Warning : only unordered tracks are affected by this option."),
|
||||
fg="gray"
|
||||
).grid(row=2, column=1)
|
||||
|
||||
|
@ -105,7 +105,7 @@ class TrackSelection:
|
|||
self.frames_track_highlight = []
|
||||
self.checkbutton_track_highlight = ttk.Checkbutton(
|
||||
self.track_highlight,
|
||||
text="Enable track highlight",
|
||||
text=self.common.translate("Enable track highlight"),
|
||||
variable=self.variable_enable_track_highlight,
|
||||
command=get_change_enable_track_filter_func(
|
||||
self.track_highlight,
|
||||
|
@ -115,14 +115,14 @@ class TrackSelection:
|
|||
)
|
||||
self.checkbutton_track_highlight.grid(row=1, column=1)
|
||||
|
||||
self.track_random_new = LabelFrame(self.root, text="Overwrite random cup new")
|
||||
self.track_random_new = LabelFrame(self.root, text=self.common.translate("Overwrite random cup new"))
|
||||
self.track_random_new.grid(row=4, column=1, sticky="NEWS")
|
||||
|
||||
self.variable_enable_track_random_new = BooleanVar(value=False)
|
||||
self.frames_track_random_new = []
|
||||
self.checkbutton_track_random_new = ttk.Checkbutton(
|
||||
self.track_random_new,
|
||||
text="Enable overwriting random \"new\" track",
|
||||
text=self.common.translate("Enable overwriting random \"new\" track"),
|
||||
variable=self.variable_enable_track_random_new,
|
||||
command=get_change_enable_track_filter_func(
|
||||
self.track_random_new,
|
||||
|
@ -157,21 +157,21 @@ class TrackSelection:
|
|||
|
||||
Button(
|
||||
self.frame_action_button,
|
||||
text="Apply change",
|
||||
text=self.common.translate("Apply change"),
|
||||
relief=RIDGE,
|
||||
command=self.apply_configuration
|
||||
).grid(row=1, column=1, sticky="W")
|
||||
|
||||
Button(
|
||||
self.frame_action_button,
|
||||
text="Save to file",
|
||||
text=self.common.translate("Save to file"),
|
||||
relief=RIDGE,
|
||||
command=self.promp_save_to_file
|
||||
).grid(row=1, column=2, sticky="E")
|
||||
|
||||
Button(
|
||||
self.frame_action_button,
|
||||
text="Load from file",
|
||||
text=self.common.translate("Load from file"),
|
||||
relief=RIDGE,
|
||||
command=self.promp_load_from_file
|
||||
).grid(row=1, column=3, sticky="E")
|
||||
|
@ -186,7 +186,7 @@ class TrackSelection:
|
|||
|
||||
frame = Frame(root)
|
||||
frame.grid(row=len(frames_filter) + 10, column=1, sticky="NEWS")
|
||||
Label(frame, text="If track's").grid(row=1, column=1)
|
||||
Label(frame, text=self.common.translate("If track's")).grid(row=1, column=1)
|
||||
track_property = ttk.Combobox(frame, values=list(self.common.ct_config.get_all_track_possibilities()))
|
||||
track_property.current(0)
|
||||
track_property.grid(row=1, column=2)
|
||||
|
@ -194,26 +194,26 @@ class TrackSelection:
|
|||
frame_equal = Frame(frame)
|
||||
entry_equal = Entry(frame_equal, width=20)
|
||||
entry_equal.grid(row=1, column=1)
|
||||
entry_equal.insert(END, "value")
|
||||
entry_equal.insert(END, self.common.translate("value"))
|
||||
|
||||
frame_in = Frame(frame)
|
||||
entry_in = Entry(frame_in, width=30)
|
||||
entry_in.grid(row=1, column=1)
|
||||
entry_in.insert(END, "value1, value2, ...")
|
||||
entry_in.insert(END, self.common.translate("value1, value2, ..."))
|
||||
|
||||
frame_between = Frame(frame)
|
||||
entry_start = Entry(frame_between, width=10)
|
||||
entry_start.grid(row=1, column=1)
|
||||
entry_start.insert(END, "value1")
|
||||
Label(frame_between, text="and").grid(row=1, column=2)
|
||||
entry_start.insert(END, self.common.translate("value1"))
|
||||
Label(frame_between, text=self.common.translate("and")).grid(row=1, column=2)
|
||||
entry_end = Entry(frame_between, width=10)
|
||||
entry_end.insert(END, "value2")
|
||||
entry_end.insert(END, self.common.translate("value2"))
|
||||
entry_end.grid(row=1, column=3)
|
||||
|
||||
frame_contains = Frame(frame)
|
||||
entry_contains = Entry(frame_contains, width=20)
|
||||
entry_contains.grid(row=1, column=1)
|
||||
entry_contains.insert(END, "value")
|
||||
entry_contains.insert(END, self.common.translate("value"))
|
||||
|
||||
condition_frames = {
|
||||
self.text_is_equal_to: frame_equal,
|
||||
|
@ -358,9 +358,9 @@ class TrackSelection:
|
|||
|
||||
def promp_save_to_file(self):
|
||||
filename = filedialog.asksaveasfilename(
|
||||
title="Save track configuration",
|
||||
title=self.common.translate("Save track configuration"),
|
||||
defaultextension=".mkwf.tc",
|
||||
filetypes=[("track configuration", "*.mkwf.tc")]
|
||||
filetypes=[(self.common.translate("track configuration"), "*.mkwf.tc")]
|
||||
)
|
||||
if filename: self.save_to_file(filename)
|
||||
|
||||
|
@ -395,8 +395,8 @@ class TrackSelection:
|
|||
|
||||
def promp_load_from_file(self):
|
||||
filename = filedialog.askopenfilename(
|
||||
title="Load track configuration",
|
||||
title=self.common.translate("Load track configuration"),
|
||||
defaultextension=".mkwf.tc",
|
||||
filetypes=[("track configuration", "*.mkwf.tc")]
|
||||
filetypes=[(self.common.translate("track configuration"), "*.mkwf.tc")]
|
||||
)
|
||||
if filename: self.load_from_file(filename)
|
32
source/Translation.py
Normal file
32
source/Translation.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
import json
|
||||
from source.definition import gamelang_to_lang
|
||||
|
||||
with open("./translation.json", encoding="utf-8") as f:
|
||||
translation_dict = json.load(f)
|
||||
|
||||
|
||||
class Translator:
|
||||
def __init__(self, common):
|
||||
self.common = common
|
||||
|
||||
def translate(self, *texts, gamelang: str = None) -> str:
|
||||
"""
|
||||
translate text into an another language in translation.json file
|
||||
:param self: object needing translation to get its language
|
||||
:param texts: all text to convert
|
||||
:param gamelang: force a destination language to convert track
|
||||
:return: translated text
|
||||
"""
|
||||
lang = gamelang_to_lang.get(gamelang, self.common.option.language)
|
||||
if lang not in translation_dict: return "".join(texts) # if no translation language is found
|
||||
|
||||
_lang_trad = translation_dict[lang]
|
||||
translated_text = ""
|
||||
for text in texts:
|
||||
if text in _lang_trad:
|
||||
translated_text += _lang_trad[text]
|
||||
else:
|
||||
print(f"No translation found for ({lang}) {text}")
|
||||
translated_text += text
|
||||
|
||||
return translated_text
|
|
@ -79,6 +79,29 @@
|
|||
"Apply": "Appliquer",
|
||||
"Folder": "Dossier",
|
||||
"selected": "sélectionné",
|
||||
"There is no pack in the ./Pack/ directory.": "Il n'y a pas de pack dans le dossier ./Pack/."
|
||||
"There is no pack in the ./Pack/ directory.": "Il n'y a pas de pack dans le dossier ./Pack/.",
|
||||
"Change track configuration": "Changer la configuration de course",
|
||||
"is equal to": "est égal à",
|
||||
"is in": "est dans",
|
||||
"is between": "est entre",
|
||||
"contains": "contient",
|
||||
"and": "et",
|
||||
"nand": "non et",
|
||||
"or": "ou",
|
||||
"nor": "non ou",
|
||||
"xor": "xor",
|
||||
"xnor": "xnor",
|
||||
"end": "fin",
|
||||
"Sort Track": "Trier les courses",
|
||||
"Sort track by": "Trier les courses par",
|
||||
"Filter Track": "Filtrer les courses",
|
||||
"Enable track filter": "Activer le filtre de course",
|
||||
"Enable track highlight": "Activer le filtre de surlignage de course",
|
||||
"Overwrite random cup new": "Écraser la course aléatoire \"nouvelle\"",
|
||||
"Enable overwriting random \"new\" track": "Activer l'écrasement de la course aléatoire \"nouvelle\"",
|
||||
"Apply change": "Appliquer les changements",
|
||||
"Save to file": "Exporter",
|
||||
"Load from file": "Importer",
|
||||
"Warning : only unordered tracks are affected by this option.": "Attention : seules les courses désordonnées sont affectées par cette option."
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue