From da5a38c17c6dbfc28da255bea960d2a33eeba8e9 Mon Sep 17 00:00:00 2001 From: Phaedrus Leeds Date: Fri, 24 Jun 2022 14:20:06 -0700 Subject: [PATCH] app: Un-split some translatable strings Also make them a bit prettier while we're here Fixes https://github.com/flatpak/flatpak/issues/4877 --- app/flatpak-cli-transaction.c | 85 +++++++++++++++++++++------------ app/flatpak-quiet-transaction.c | 50 ++++++++++++++----- 2 files changed, 92 insertions(+), 43 deletions(-) diff --git a/app/flatpak-cli-transaction.c b/app/flatpak-cli-transaction.c index 18697923..85062180 100644 --- a/app/flatpak-cli-transaction.c +++ b/app/flatpak-cli-transaction.c @@ -195,28 +195,6 @@ install_authenticator (FlatpakTransaction *old_transaction, return; } -static char * -op_type_to_string (FlatpakTransactionOperationType operation_type) -{ - switch (operation_type) - { - case FLATPAK_TRANSACTION_OPERATION_INSTALL: - return _("install"); - - case FLATPAK_TRANSACTION_OPERATION_UPDATE: - return _("update"); - - case FLATPAK_TRANSACTION_OPERATION_INSTALL_BUNDLE: - return _("install bundle"); - - case FLATPAK_TRANSACTION_OPERATION_UNINSTALL: - return _("uninstall"); - - default: - return "Unknown type"; /* Should not happen */ - } -} - static gboolean redraw (FlatpakCliTransaction *self) { @@ -497,6 +475,14 @@ operation_error (FlatpakTransaction *transaction, g_autofree char *msg = NULL; gboolean non_fatal = (detail & FLATPAK_TRANSACTION_ERROR_DETAILS_NON_FATAL) != 0; g_autofree char *text = NULL; + const char *on = ""; + const char *off = ""; + + if (flatpak_fancy_output ()) + { + on = FLATPAK_ANSI_BOLD_ON; + off = FLATPAK_ANSI_BOLD_OFF; + } if (g_error_matches (error, FLATPAK_ERROR, FLATPAK_ERROR_SKIPPED)) { @@ -519,13 +505,13 @@ operation_error (FlatpakTransaction *transaction, set_op_progress (self, op, "✗"); if (g_error_matches (error, FLATPAK_ERROR, FLATPAK_ERROR_ALREADY_INSTALLED)) - msg = g_strdup_printf (_("%s already installed"), flatpak_ref_get_name (rref)); + msg = g_strdup_printf (_("%s%s%s already installed"), on, flatpak_ref_get_name (rref), off); else if (g_error_matches (error, FLATPAK_ERROR, FLATPAK_ERROR_NOT_INSTALLED)) - msg = g_strdup_printf (_("%s not installed"), flatpak_ref_get_name (rref)); + msg = g_strdup_printf (_("%s%s%s not installed"), on, flatpak_ref_get_name (rref), off); else if (g_error_matches (error, FLATPAK_ERROR, FLATPAK_ERROR_NOT_INSTALLED)) - msg = g_strdup_printf (_("%s not installed"), flatpak_ref_get_name (rref)); + msg = g_strdup_printf (_("%s%s%s not installed"), on, flatpak_ref_get_name (rref), off); else if (g_error_matches (error, FLATPAK_ERROR, FLATPAK_ERROR_NEED_NEW_FLATPAK)) - msg = g_strdup_printf (_("%s needs a later flatpak version"), flatpak_ref_get_name (rref)); + msg = g_strdup_printf (_("%s%s%s needs a later flatpak version"), on, flatpak_ref_get_name (rref), off); else if (g_error_matches (error, FLATPAK_ERROR, FLATPAK_ERROR_OUT_OF_SPACE)) msg = g_strdup (_("Not enough disk space to complete this operation")); else if (error) @@ -534,12 +520,49 @@ operation_error (FlatpakTransaction *transaction, msg = g_strdup (_("(internal error, please report)")); if (!non_fatal && self->first_operation_error == NULL) - g_propagate_prefixed_error (&self->first_operation_error, - g_error_copy (error), - _("Failed to %s %s: "), - op_type_to_string (op_type), flatpak_ref_get_name (rref)); + { + /* Here we go to great lengths not to split the sentences. See + * https://wiki.gnome.org/TranslationProject/DevGuidelines/Never%20split%20sentences + */ + switch (op_type) + { + case FLATPAK_TRANSACTION_OPERATION_INSTALL: + g_propagate_prefixed_error (&self->first_operation_error, + g_error_copy (error), + _("Failed to install %s%s%s: "), + on, flatpak_ref_get_name (rref), off); + break; - text = g_strconcat (non_fatal ? _("Warning:") : _("Error:"), " ", msg, NULL); + case FLATPAK_TRANSACTION_OPERATION_UPDATE: + g_propagate_prefixed_error (&self->first_operation_error, + g_error_copy (error), + _("Failed to update %s%s%s: "), + on, flatpak_ref_get_name (rref), off); + break; + + case FLATPAK_TRANSACTION_OPERATION_INSTALL_BUNDLE: + g_propagate_prefixed_error (&self->first_operation_error, + g_error_copy (error), + _("Failed to install bundle %s%s%s: "), + on, flatpak_ref_get_name (rref), off); + break; + + case FLATPAK_TRANSACTION_OPERATION_UNINSTALL: + g_propagate_prefixed_error (&self->first_operation_error, + g_error_copy (error), + _("Failed to uninstall %s%s%s: "), + on, flatpak_ref_get_name (rref), off); + break; + + default: + g_assert_not_reached (); + } + } + + if (non_fatal) + text = g_strconcat (_("Warning: "), msg, NULL); + else + text = g_strconcat (_("Error: "), msg, NULL); if (flatpak_fancy_output ()) { diff --git a/app/flatpak-quiet-transaction.c b/app/flatpak-quiet-transaction.c index a820c082..9fde8a3d 100644 --- a/app/flatpak-quiet-transaction.c +++ b/app/flatpak-quiet-transaction.c @@ -91,25 +91,55 @@ new_operation (FlatpakTransaction *transaction, } } -static char * -op_type_to_string (FlatpakTransactionOperationType operation_type) +static void +print_op_error_msg (FlatpakTransactionOperationType operation_type, + FlatpakRef *rref, + const char *msg, + gboolean non_fatal) { + /* Here we go to great lengths not to split the sentences. See + * https://wiki.gnome.org/TranslationProject/DevGuidelines/Never%20split%20sentences + */ switch (operation_type) { case FLATPAK_TRANSACTION_OPERATION_INSTALL: - return _("install"); + if (non_fatal) + g_printerr (_("Warning: Failed to install %s: %s\n"), + flatpak_ref_get_name (rref), msg); + else + g_printerr (_("Error: Failed to install %s: %s\n"), + flatpak_ref_get_name (rref), msg); + break; case FLATPAK_TRANSACTION_OPERATION_UPDATE: - return _("update"); + if (non_fatal) + g_printerr (_("Warning: Failed to update %s: %s\n"), + flatpak_ref_get_name (rref), msg); + else + g_printerr (_("Error: Failed to update %s: %s\n"), + flatpak_ref_get_name (rref), msg); + break; case FLATPAK_TRANSACTION_OPERATION_INSTALL_BUNDLE: - return _("install bundle"); + if (non_fatal) + g_printerr (_("Warning: Failed to install bundle %s: %s\n"), + flatpak_ref_get_name (rref), msg); + else + g_printerr (_("Error: Failed to install bundle %s: %s\n"), + flatpak_ref_get_name (rref), msg); + break; case FLATPAK_TRANSACTION_OPERATION_UNINSTALL: - return _("uninstall"); + if (non_fatal) + g_printerr (_("Warning: Failed to uninstall %s: %s\n"), + flatpak_ref_get_name (rref), msg); + else + g_printerr (_("Error: Failed to uninstall %s: %s\n"), + flatpak_ref_get_name (rref), msg); + break; default: - return "Unknown type"; /* Should not happen */ + g_assert_not_reached (); } } @@ -145,11 +175,7 @@ operation_error (FlatpakTransaction *transaction, else msg = g_strdup (error->message); - g_printerr (_("%s Failed to %s %s: %s\n"), - non_fatal ? _("Warning:") : _("Error:"), - op_type_to_string (op_type), - flatpak_ref_get_name (rref), - msg); + print_op_error_msg (op_type, rref, msg, non_fatal); if (non_fatal) return TRUE; /* Continue */