From ce715862fe4c8c2c1f2ed1a4a3b6eb3cb37c7606 Mon Sep 17 00:00:00 2001 From: fell Date: Mon, 19 Feb 2018 11:50:10 +0100 Subject: [PATCH] Mark forgotten error messages in gnc-sx-instance-model.c translatable and report them bilingual: * in g_critical untranslated and * in g_list_append translated. --- src/app-utils/gnc-sx-instance-model.c | 75 +++++++++------------------ src/app-utils/gnc-sx-instance-model.h | 11 ++++ 2 files changed, 35 insertions(+), 51 deletions(-) diff --git a/src/app-utils/gnc-sx-instance-model.c b/src/app-utils/gnc-sx-instance-model.c index b3f95ab2e7..832eeb8b54 100644 --- a/src/app-utils/gnc-sx-instance-model.c +++ b/src/app-utils/gnc-sx-instance-model.c @@ -991,14 +991,10 @@ _get_template_split_account(const SchedXaction* sx, const Split *template_split, NULL); if (kvp_val == NULL) { - gchar *err = g_strdup_printf("Null account kvp value for SX [%s], " - "cancelling creation.", - xaccSchedXactionGetName(sx)); - g_critical("%s", err); - if (creation_errors != NULL) - *creation_errors = g_list_append(*creation_errors, err); - else - g_free(err); +/* Translators: A list of error messages from the Scheduled Transactions (SX). + * They might appear in their editor or in "Since last run". */ + gchar *err = N_("Null account kvp value for SX [%s], cancelling creation."); + REPORT_ERROR(creation_errors, err, xaccSchedXactionGetName(sx)); return FALSE; } acct_guid = kvp_value_get_guid( kvp_val ); @@ -1006,15 +1002,9 @@ _get_template_split_account(const SchedXaction* sx, const Split *template_split, if (*split_acct == NULL) { char guid_str[GUID_ENCODING_LENGTH+1]; - gchar* err; + gchar* err = N_("Unknown account for guid [%s], cancelling SX [%s] creation."); guid_to_string_buff((const GncGUID*)acct_guid, guid_str); - err = g_strdup_printf ("Unknown account for guid [%s], cancelling SX [%s] creation.", - guid_str, xaccSchedXactionGetName(sx)); - g_critical("%s", err); - if (creation_errors != NULL) - *creation_errors = g_list_append(*creation_errors, err); - else - g_free(err); + REPORT_ERROR(creation_errors, err, guid_str, xaccSchedXactionGetName(sx)); return FALSE; } @@ -1065,18 +1055,14 @@ _get_sx_formula_value(const SchedXaction* sx, const Split *template_split, gnc_n &parseErrorLoc, parser_vars)) { - gchar *err = g_strdup_printf ("Error parsing SX [%s] key [%s]=formula [%s] at [%s]: %s", - xaccSchedXactionGetName(sx), - formula_key, - formula_str, - parseErrorLoc, - gnc_exp_parser_error_string()); - g_critical ("%s", err); - if (creation_errors != NULL) - *creation_errors = g_list_append(*creation_errors, err); - else - g_free (err); - } + gchar *err = N_("Error parsing SX [%s] key [%s]=formula [%s] at [%s]: %s."); + REPORT_ERROR(creation_errors, err, + xaccSchedXactionGetName(sx), + formula_key, + formula_str, + parseErrorLoc, + gnc_exp_parser_error_string()); + } if (parser_vars != NULL) { @@ -1123,14 +1109,9 @@ split_apply_formulas (const Split *split, SxTxnCreationData* creation_data) gncn_error = gnc_numeric_check(final); if (gncn_error != GNC_ERROR_OK) { - gchar *err = g_strdup_printf ("error %d in SX [%s] final gnc_numeric value, using 0 instead", + gchar *err = N_("Error %d in SX [%s] final gnc_numeric value, using 0 instead."); + REPORT_ERROR(creation_data->creation_errors, err, gncn_error, xaccSchedXactionGetName(sx)); - g_critical("%s", err); - if (creation_data->creation_errors != NULL) - *creation_data->creation_errors = - g_list_append(*creation_data->creation_errors, err); - else - g_free (err); final = gnc_numeric_zero(); } return final; @@ -1754,28 +1735,20 @@ create_cashflow_helper(Transaction *template_txn, void *user_data) gncn_error = gnc_numeric_check(final); if (gncn_error != GNC_ERROR_OK) { - gchar* err = g_strdup_printf ("error %d in SX [%s] final gnc_numeric value, using 0 instead", - gncn_error, xaccSchedXactionGetName(creation_data->sx)); - g_critical("%s", err); - if (creation_data->creation_errors != NULL) - *creation_data->creation_errors = g_list_append(*creation_data->creation_errors, err); - else - g_free (err); + gchar* err = N_("Error %d in SX [%s] final gnc_numeric value, using 0 instead."); + REPORT_ERROR(creation_data->creation_errors, err, + gncn_error, xaccSchedXactionGetName(creation_data->sx)); final = gnc_numeric_zero(); } /* Print error message if we would have needed an exchange rate */ if (! gnc_commodity_equal(split_cmdty, first_cmdty)) { - gchar* err = g_strdup_printf ("No exchange rate available in SX [%s] for %s -> %s, value is zero", - xaccSchedXactionGetName(creation_data->sx), - gnc_commodity_get_mnemonic(split_cmdty), - gnc_commodity_get_mnemonic(first_cmdty)); - g_critical("%s", err); - if (creation_data->creation_errors != NULL) - *creation_data->creation_errors = g_list_append(*creation_data->creation_errors, err); - else - g_free(err); + gchar *err = N_("No exchange rate available in SX [%s] for %s -> %s, value is zero."); + REPORT_ERROR(creation_data->creation_errors, err, + xaccSchedXactionGetName(creation_data->sx), + gnc_commodity_get_mnemonic(split_cmdty), + gnc_commodity_get_mnemonic(first_cmdty)); final = gnc_numeric_zero(); } diff --git a/src/app-utils/gnc-sx-instance-model.h b/src/app-utils/gnc-sx-instance-model.h index a31ef1d6d4..22f5d3222e 100644 --- a/src/app-utils/gnc-sx-instance-model.h +++ b/src/app-utils/gnc-sx-instance-model.h @@ -258,4 +258,15 @@ GHashTable* gnc_sx_all_instantiate_cashflow_all(GDate range_start, GDate range_e G_END_DECLS + +/** Report errors bilingual: + * in g_critical untranslated and + * in g_list_append translated. + */ +#define REPORT_ERROR(list, format, ...) do { \ + g_critical(format, __VA_ARGS__); \ + if (list != NULL) \ + *list = g_list_append(*list, g_strdup_printf(_(format), __VA_ARGS__)); \ +} while (0) + #endif // _GNC_SX_INSTANCE_MODEL_H