From dae2ea8356931a34e198c83c7dac6858fee61248 Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Wed, 16 Sep 2020 23:41:04 +0200 Subject: [PATCH] Expose C_ function (gettext with context string) to guile code First use is for the document link short code (L) --- bindings/core-utils.i | 15 +++++++++++++++ bindings/guile/core-utils.scm | 2 ++ gnucash/report/trep-engine.scm | 4 ++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/bindings/core-utils.i b/bindings/core-utils.i index 8695d64cdb..27976f2136 100644 --- a/bindings/core-utils.i +++ b/bindings/core-utils.i @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -158,6 +159,20 @@ gchar *gnc_locale_name (void); %rename ("gnc:gettext") gettext; extern const char* gettext(const char*); +%rename ("gnc:C_gettext") wrap_C_; +%inline %{ + /* This helper function wraps the C_() macro in to a function. + Direct wrapping results in a compiler error on direct string concatenation + inside the macro expansion, so I'm making a detour via g_strconcat */ + const char* wrap_C_(const char* context, const char* msg); + const char* wrap_C_(const char* context, const char* msg) + { + gchar* combo = g_strconcat (context, "\004", msg, NULL); + const gchar* translated = g_dpgettext (NULL, combo, strlen (context) + 1); + g_free (combo); + return translated; + } +%} %rename ("gnc-utf8?") wrap_gnc_utf8_validate; %inline %{ /* This helper function wraps gnc_utf8_validate() into a predicate. */ diff --git a/bindings/guile/core-utils.scm b/bindings/guile/core-utils.scm index 5d037bc46c..32179f1493 100644 --- a/bindings/guile/core-utils.scm +++ b/bindings/guile/core-utils.scm @@ -27,6 +27,7 @@ (define-module (gnucash core-utils) #:export (N_ G_ + C_ gnc:version)) ;; Guile 2 needs to find the symbols from the extension at compile time already @@ -42,6 +43,7 @@ ;; gettext functions (define G_ gnc:gettext) +(define C_ gnc:C-gettext) (define-syntax-rule (N_ x) x) ;; the following will define _ to call gnc:gettext for guile up to diff --git a/gnucash/report/trep-engine.scm b/gnucash/report/trep-engine.scm index 87613cc06d..894505083b 100644 --- a/gnucash/report/trep-engine.scm +++ b/gnucash/report/trep-engine.scm @@ -1255,8 +1255,8 @@ be excluded from periodic reporting.") (gnc:html-transaction-doclink-anchor (xaccSplitGetParent split) ;; Translators: 'L' is short for Linked Document - (G_ "L")) - (G_ "L")))))))) + (C_ "Column header for 'Document Link'" "L")) + (C_ "Column header for 'Document Link'" "L")))))))) (add-if (column-uses? 'price) (vector (G_ "Price")