added translate_external for message that need translation from outside of the installer.

This commit is contained in:
Faraphel 2022-08-17 18:43:40 +02:00
parent d3ca353ecd
commit 433bf08b9b
6 changed files with 38 additions and 13 deletions

View file

@ -1,4 +1,10 @@
{ {
"specific_settings_description": {
"text": {
"fr": "* Ceci activera le mode \"triche\"",
"en": "* This will enable the \"cheat\" mode"
}
},
"installation_completed": { "installation_completed": {
"text": { "text": {
"fr": "Merci d'avoir téléchargé {{ mod_config.name }} !\nSi vous avez un problème en démarrant le jeu avec Dolphin, essayer dans Configurer > Avancé > Modifier la taille de la mémoire émulée et mettre MEM2 à 128MB\n\nAmusez-vous !", "fr": "Merci d'avoir téléchargé {{ mod_config.name }} !\nSi vous avez un problème en démarrant le jeu avec Dolphin, essayer dans Configurer > Avancé > Modifier la taille de la mémoire émulée et mettre MEM2 à 128MB\n\nAmusez-vous !",

View file

@ -29,7 +29,6 @@
"USE": "Use", "USE": "Use",
"THREADS": "threads", "THREADS": "threads",
"MESSAGE_FROM_MOD_AUTHOR": "Message from the author", "MESSAGE_FROM_MOD_AUTHOR": "Message from the author",
"NO_MESSAGE_FROM_AUTHOR": "< The author didn't left any message >",
"GLOBAL_MOD_SETTINGS": "Global mod settings", "GLOBAL_MOD_SETTINGS": "Global mod settings",
"SPECIFIC_MOD_SETTINGS": "Specific mod settings", "SPECIFIC_MOD_SETTINGS": "Specific mod settings",
"CONFIGURE_MYSTUFF_PATCH": "Configure the MyStuff patchs", "CONFIGURE_MYSTUFF_PATCH": "Configure the MyStuff patchs",

View file

@ -30,7 +30,6 @@
"USE": "Utiliser", "USE": "Utiliser",
"THREADS": "threads", "THREADS": "threads",
"MESSAGE_FROM_MOD_AUTHOR": "Message de l'auteur", "MESSAGE_FROM_MOD_AUTHOR": "Message de l'auteur",
"NO_MESSAGE_FROM_AUTHOR": "< L'auteur n'a pas laissé de message >",
"GLOBAL_MOD_SETTINGS": "Paramètre global de mod", "GLOBAL_MOD_SETTINGS": "Paramètre global de mod",
"SPECIFIC_MOD_SETTINGS": "Paramètre spécifique de mod", "SPECIFIC_MOD_SETTINGS": "Paramètre spécifique de mod",
"CONFIGURE_MYSTUFF_PATCH": "Configurer les patchs MyStuff", "CONFIGURE_MYSTUFF_PATCH": "Configurer les patchs MyStuff",

View file

@ -14,7 +14,7 @@ from source.mkw.Game import Game
from source.mkw.ModConfig import ModConfig from source.mkw.ModConfig import ModConfig
from source.option import Option from source.option import Option
from source.progress import Progress from source.progress import Progress
from source.translation import translate as _ from source.translation import translate as _, translate_external
from source import plugins from source import plugins
from source import * from source import *
import os import os
@ -432,15 +432,17 @@ class ButtonInstall(ttk.Button):
) )
) )
message_texts = mod_config.messages.get("installation_completed", {}).get("text", {}) message: str = translate_external(
message = message_texts.get(self.root.options["language"]) mod_config,
if message is None: message = message_texts.get("*") self.root.options["language"],
if message is None: message = _('NO_MESSAGE_FROM_AUTHOR') mod_config.messages.get("installation_completed", {}).get("text", {})
message = mod_config.multiple_safe_eval(message)() )
messagebox.showinfo( messagebox.showinfo(
_("INSTALLATION_COMPLETED"), _("INSTALLATION_COMPLETED"),
f"{_('INSTALLATION_FINISHED_WITH_SUCCESS')}\n{_('MESSAGE_FROM_MOD_AUTHOR')} :\n\n{message}" f"{_('INSTALLATION_FINISHED_WITH_SUCCESS')}" + (
f"\n{_('MESSAGE_FROM_MOD_AUTHOR')} :\n\n{message}" if message != "" else ""
)
) )
finally: finally:

View file

@ -2,7 +2,7 @@ import tkinter
from tkinter import ttk from tkinter import ttk
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from source.translation import translate as _ from source.translation import translate as _, translate_external
if TYPE_CHECKING: if TYPE_CHECKING:
from source.mkw.ModConfig import ModConfig from source.mkw.ModConfig import ModConfig
@ -63,9 +63,11 @@ class FrameSettings(ttk.Frame):
return lambda event: enabled_variable.set(True) return lambda event: enabled_variable.set(True)
for index, (settings_name, settings_data) in enumerate(settings.items()): for index, (settings_name, settings_data) in enumerate(settings.items()):
text = settings_data.text.get(self.root.options["language"]) text = translate_external(
if text is None: text = settings_data.text.get("*") self.master.master.mod_config,
if text is None: text = settings_name self.root.options["language"],
settings_data.text,
)
enabled_variable = tkinter.BooleanVar(value=False) enabled_variable = tkinter.BooleanVar(value=False)
checkbox = ttk.Checkbutton(self, text=text, variable=enabled_variable) checkbox = ttk.Checkbutton(self, text=text, variable=enabled_variable)

View file

@ -1,5 +1,9 @@
import json import json
from pathlib import Path from pathlib import Path
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from source.mkw.ModConfig import ModConfig
self = __import__(__name__) self = __import__(__name__)
@ -28,5 +32,18 @@ def translate(*text) -> str:
]) ])
def translate_external(mod_config: "ModConfig", language: str, message_texts: dict[str, str], default: str = "") -> str:
"""
Translate any message that is not from the game.
:param mod_config: the ModConfig object
:param language: the language to translate to
:param message_texts: a dictionary with the translation
:param default: the default message if no translation are found
:return: the translated message
"""
message = message_texts.get(language)
if message is None: message = message_texts.get("*")
if message is None: message = default
return mod_config.multiple_safe_eval(message)()