Misc fixes, try to implement locale strings

This commit is contained in:
Alexandre Aubin 2021-09-04 20:22:28 +02:00
parent c8791a9834
commit 778c67540c
3 changed files with 28 additions and 19 deletions

View file

@ -21,6 +21,8 @@
"app_change_url_identical_domains": "The old and new domain/url_path are identical ('{domain}{path}'), nothing to do.", "app_change_url_identical_domains": "The old and new domain/url_path are identical ('{domain}{path}'), nothing to do.",
"app_change_url_no_script": "The app '{app_name}' doesn't support URL modification yet. Maybe you should upgrade it.", "app_change_url_no_script": "The app '{app_name}' doesn't support URL modification yet. Maybe you should upgrade it.",
"app_change_url_success": "{app} URL is now {domain}{path}", "app_change_url_success": "{app} URL is now {domain}{path}",
"app_config_unable_to_apply": "Failed to apply config panel values.",
"app_config_unable_to_read": "Failed to read config panel values.",
"app_extraction_failed": "Could not extract the installation files", "app_extraction_failed": "Could not extract the installation files",
"app_full_domain_unavailable": "Sorry, this app must be installed on a domain of its own, but other apps are already installed on the domain '{domain}'. You could use a subdomain dedicated to this app instead.", "app_full_domain_unavailable": "Sorry, this app must be installed on a domain of its own, but other apps are already installed on the domain '{domain}'. You could use a subdomain dedicated to this app instead.",
"app_id_invalid": "Invalid app ID", "app_id_invalid": "Invalid app ID",
@ -139,6 +141,7 @@
"certmanager_self_ca_conf_file_not_found": "Could not find configuration file for self-signing authority (file: {file})", "certmanager_self_ca_conf_file_not_found": "Could not find configuration file for self-signing authority (file: {file})",
"certmanager_unable_to_parse_self_CA_name": "Could not parse name of self-signing authority (file: {file})", "certmanager_unable_to_parse_self_CA_name": "Could not parse name of self-signing authority (file: {file})",
"certmanager_warning_subdomain_dns_record": "Subdomain '{subdomain}' does not resolve to the same IP address as '{domain}'. Some features will not be available until you fix this and regenerate the certificate.", "certmanager_warning_subdomain_dns_record": "Subdomain '{subdomain}' does not resolve to the same IP address as '{domain}'. Some features will not be available until you fix this and regenerate the certificate.",
"config_apply_failed": "Applying the new configuration failed: {error}",
"confirm_app_install_danger": "DANGER! This app is known to be still experimental (if not explicitly not working)! You should probably NOT install it unless you know what you are doing. NO SUPPORT will be provided if this app doesn't work or breaks your system... If you are willing to take that risk anyway, type '{answers}'", "confirm_app_install_danger": "DANGER! This app is known to be still experimental (if not explicitly not working)! You should probably NOT install it unless you know what you are doing. NO SUPPORT will be provided if this app doesn't work or breaks your system... If you are willing to take that risk anyway, type '{answers}'",
"confirm_app_install_thirdparty": "DANGER! This app is not part of YunoHost's app catalog. Installing third-party apps may compromise the integrity and security of your system. You should probably NOT install it unless you know what you are doing. NO SUPPORT will be provided if this app doesn't work or breaks your system... If you are willing to take that risk anyway, type '{answers}'", "confirm_app_install_thirdparty": "DANGER! This app is not part of YunoHost's app catalog. Installing third-party apps may compromise the integrity and security of your system. You should probably NOT install it unless you know what you are doing. NO SUPPORT will be provided if this app doesn't work or breaks your system... If you are willing to take that risk anyway, type '{answers}'",
"confirm_app_install_warning": "Warning: This app may work, but is not well-integrated in YunoHost. Some features such as single sign-on and backup/restore might not be available. Install anyway? [{answers}] ", "confirm_app_install_warning": "Warning: This app may work, but is not well-integrated in YunoHost. Some features such as single sign-on and backup/restore might not be available. Install anyway? [{answers}] ",
@ -389,8 +392,8 @@
"log_app_change_url": "Change the URL of the '{}' app", "log_app_change_url": "Change the URL of the '{}' app",
"log_app_config_apply": "Apply config to the '{}' app", "log_app_config_apply": "Apply config to the '{}' app",
"log_app_config_get": "Get a specific setting from config panel of the '{}' app", "log_app_config_get": "Get a specific setting from config panel of the '{}' app",
"log_app_config_show": "Show the config panel of the '{}' app",
"log_app_config_set": "Apply config to the '{}' app", "log_app_config_set": "Apply config to the '{}' app",
"log_app_config_show": "Show the config panel of the '{}' app",
"log_app_install": "Install the '{}' app", "log_app_install": "Install the '{}' app",
"log_app_makedefault": "Make '{}' the default app", "log_app_makedefault": "Make '{}' the default app",
"log_app_remove": "Remove the '{}' app", "log_app_remove": "Remove the '{}' app",
@ -596,6 +599,7 @@
"service_disabled": "The service '{service}' will not be started anymore when system boots.", "service_disabled": "The service '{service}' will not be started anymore when system boots.",
"service_enable_failed": "Could not make the service '{service}' automatically start at boot.\n\nRecent service logs:{logs}", "service_enable_failed": "Could not make the service '{service}' automatically start at boot.\n\nRecent service logs:{logs}",
"service_enabled": "The service '{service}' will now be automatically started during system boots.", "service_enabled": "The service '{service}' will now be automatically started during system boots.",
"service_not_reloading_because_conf_broken": "Not reloading/restarting service '{name}' because it configuration is broken: {errors}",
"service_regen_conf_is_deprecated": "'yunohost service regen-conf' is deprecated! Please use 'yunohost tools regen-conf' instead.", "service_regen_conf_is_deprecated": "'yunohost service regen-conf' is deprecated! Please use 'yunohost tools regen-conf' instead.",
"service_reload_failed": "Could not reload the service '{service}'\n\nRecent service logs:{logs}", "service_reload_failed": "Could not reload the service '{service}'\n\nRecent service logs:{logs}",
"service_reload_or_restart_failed": "Could not reload or restart the service '{service}'\n\nRecent service logs:{logs}", "service_reload_or_restart_failed": "Could not reload or restart the service '{service}'\n\nRecent service logs:{logs}",

View file

@ -1823,9 +1823,9 @@ ynh_app_config_run $1
ret, values = hook_exec(config_script, args=[action], env=env) ret, values = hook_exec(config_script, args=[action], env=env)
if ret != 0: if ret != 0:
if action == "show": if action == "show":
raise YunohostError("app_config_unable_to_read_values") raise YunohostError("app_config_unable_to_read")
else: else:
raise YunohostError("app_config_unable_to_apply_values_correctly") raise YunohostError("app_config_unable_to_apply")
return values return values

View file

@ -31,6 +31,7 @@ from moulinette import Moulinette, m18n
from moulinette.utils.log import getActionLogger from moulinette.utils.log import getActionLogger
from moulinette.utils.process import check_output from moulinette.utils.process import check_output
from moulinette.utils.filesystem import ( from moulinette.utils.filesystem import (
write_to_file,
read_toml, read_toml,
read_yaml, read_yaml,
write_to_yaml, write_to_yaml,
@ -127,14 +128,14 @@ class ConfigPanel:
# N.B. : KeyboardInterrupt does not inherit from Exception # N.B. : KeyboardInterrupt does not inherit from Exception
except (KeyboardInterrupt, EOFError): except (KeyboardInterrupt, EOFError):
error = m18n.n("operation_interrupted") error = m18n.n("operation_interrupted")
logger.error(m18n.n("config_failed", error=error)) logger.error(m18n.n("config_apply_failed", error=error))
raise raise
# Something wrong happened in Yunohost's code (most probably hook_exec) # Something wrong happened in Yunohost's code (most probably hook_exec)
except Exception: except Exception:
import traceback import traceback
error = m18n.n("unexpected_error", error="\n" + traceback.format_exc()) error = m18n.n("unexpected_error", error="\n" + traceback.format_exc())
logger.error(m18n.n("config_failed", error=error)) logger.error(m18n.n("config_apply_failed", error=error))
raise raise
finally: finally:
# Delete files uploaded from API # Delete files uploaded from API
@ -154,10 +155,11 @@ class ConfigPanel:
return read_toml(self.config_path) return read_toml(self.config_path)
def _get_config_panel(self): def _get_config_panel(self):
# Split filter_key # Split filter_key
filter_key = dict(enumerate(self.filter_key.split("."))) filter_key = self.filter_key.split(".")
if len(filter_key) > 3: if len(filter_key) > 3:
raise YunohostError("config_too_much_sub_keys") raise YunohostError("config_too_many_sub_keys", key=self.filter_key)
if not os.path.exists(self.config_path): if not os.path.exists(self.config_path):
return None return None
@ -166,7 +168,7 @@ class ConfigPanel:
# Check TOML config panel is in a supported version # Check TOML config panel is in a supported version
if float(toml_config_panel["version"]) < CONFIG_PANEL_VERSION_SUPPORTED: if float(toml_config_panel["version"]) < CONFIG_PANEL_VERSION_SUPPORTED:
raise YunohostError( raise YunohostError(
"config_too_old_version", version=toml_config_panel["version"] "config_version_not_supported", version=toml_config_panel["version"]
) )
# Transform toml format into internal format # Transform toml format into internal format
@ -187,6 +189,13 @@ class ConfigPanel:
# optional choices pattern limit min max step accept redact # optional choices pattern limit min max step accept redact
} }
#
# FIXME : this is hella confusing ...
# from what I understand, the purpose is to have some sort of "deep_update"
# to apply the defaults onto the loaded toml ...
# in that case we probably want to get inspiration from
# https://stackoverflow.com/questions/3232943/update-value-of-a-nested-dictionary-of-varying-depth
#
def convert(toml_node, node_type): def convert(toml_node, node_type):
"""Convert TOML in internal format ('full' mode used by webadmin) """Convert TOML in internal format ('full' mode used by webadmin)
Here are some properties of 1.0 config panel in toml: Here are some properties of 1.0 config panel in toml:
@ -456,7 +465,7 @@ class YunoHostArgumentFormatParser(object):
if self.operation_logger: if self.operation_logger:
self.operation_logger.data_to_redact.extend(data_to_redact) self.operation_logger.data_to_redact.extend(data_to_redact)
elif data_to_redact: elif data_to_redact:
raise YunohostError("app_argument_cant_redact", arg=question.name) raise YunohostError(f"Can't redact {question.name} because no operation logger available in the context", raw_msg=True)
return question.value return question.value
@ -729,7 +738,7 @@ class FileArgumentParser(YunoHostArgumentFormatParser):
raise YunohostValidationError( raise YunohostValidationError(
"app_argument_invalid", "app_argument_invalid",
field=question.name, field=question.name,
error=m18n.n("invalid_number1"), error=m18n.n("file_does_not_exists"),
) )
if question.value in [None, ""] or not question.accept: if question.value in [None, ""] or not question.accept:
return return
@ -743,7 +752,7 @@ class FileArgumentParser(YunoHostArgumentFormatParser):
raise YunohostValidationError( raise YunohostValidationError(
"app_argument_invalid", "app_argument_invalid",
field=question.name, field=question.name,
error=m18n.n("invalid_number2"), error=m18n.n("file_extension_not_accepted"),
) )
def _post_parse_value(self, question): def _post_parse_value(self, question):
@ -768,19 +777,15 @@ class FileArgumentParser(YunoHostArgumentFormatParser):
# i.e. os.path.join("/foo", "/etc/passwd") == "/etc/passwd" # i.e. os.path.join("/foo", "/etc/passwd") == "/etc/passwd"
file_path = os.path.normpath(upload_dir + "/" + filename) file_path = os.path.normpath(upload_dir + "/" + filename)
if not file_path.startswith(upload_dir + "/"): if not file_path.startswith(upload_dir + "/"):
raise YunohostError("relative_parent_path_in_filename_forbidden") raise YunohostError("file_relative_parent_path_in_filename_forbidden")
i = 2 i = 2
while os.path.exists(file_path): while os.path.exists(file_path):
file_path = os.path.normpath(upload_dir + "/" + filename + (".%d" % i)) file_path = os.path.normpath(upload_dir + "/" + filename + (".%d" % i))
i += 1 i += 1
content = question.value["content"] content = question.value["content"]
try:
with open(file_path, "wb") as f: write_to_file(file_path, b64decode(content), file_mode="wb")
f.write(b64decode(content))
except IOError as e:
raise YunohostError("cannot_write_file", file=file_path, error=str(e))
except Exception as e:
raise YunohostError("error_writing_file", file=file_path, error=str(e))
question.value = file_path question.value = file_path
return question.value return question.value