Add translation context for statistical "Error"
authorTheppitak Karoonboonyanan <theppitak@gmail.com>
Fri, 11 Oct 2024 09:46:06 +0000 (16:46 +0700)
committerBen Pfaff <blp@cs.stanford.edu>
Mon, 21 Oct 2024 16:51:02 +0000 (09:51 -0700)
Since gnulib's gettext.h defines pgettext() as macro with string
catenation, it's impossible to add pgettext version API for
pivot_value_new_text().  Rather, the pivot_value creation part is
split into pivot_value_new_text_translate() and let's expand
pgettext() upon calling it.

With this, C_() and NC_() macros are defined for translation with
context.

Fixing bug #66244.

po/automake.mk
src/language/commands/glm.c
src/output/pivot-table.c
src/output/pivot-table.h

index 163ec80f230e156dac2570826e46614bec5a91c8..58c6ff8c6ca7e6c207417daa9f5ef4dc941a4f05 100644 (file)
@@ -64,7 +64,7 @@ ALL_TRANSLATABLE_FILES = \
 
 $(POTFILE): $(ALL_TRANSLATABLE_FILES) Makefile
        @$(MKDIR_P) po
-       $(AM_V_GEN)$(XGETTEXT) $(XGETTEXT_OPTIONS) $(TRANSLATABLE_FILES) --language=C --keyword=_ --keyword=N_ -o $@,tmp
+       $(AM_V_GEN)$(XGETTEXT) $(XGETTEXT_OPTIONS) $(TRANSLATABLE_FILES) --language=C --keyword=_ --keyword=N_ --keyword=C_:1c,2 --keyword=NC_ -o $@,tmp
        $(AM_V_at)test -z "$(UI_FILES)" || $(XGETTEXT) $(XGETTEXT_OPTIONS) -j $(UI_FILES) --language=Glade -o $@,tmp
        $(AM_V_at)$(XGETTEXT) $(XGETTEXT_OPTIONS) -j doc/org.gnu.pspp.metainfo.xml.in -o $@,tmp
        $(AM_V_at)$(XGETTEXT) $(XGETTEXT_OPTIONS) -j doc/org.gnu.pspp.desktop.in -o $@,tmp
index 05ab9bf9ca96710aab5ab2c0255bbd4135db49f9..077fecc5281ce82e79098734ac9509e70381da8e 100644 (file)
@@ -48,6 +48,8 @@
 #include "gettext.h"
 #define N_(msgid) msgid
 #define _(msgid) gettext (msgid)
+#define NC_(msgctxt,msgid) msgid
+#define C_(msgctxt,msgid) pgettext (msgctxt, msgid)
 
 struct glm_spec
   {
@@ -718,8 +720,9 @@ output_glm (const struct glm_spec *cmd, const struct glm_workspace *ws)
   }
 
   {
-    int row = pivot_category_create_leaf (source->root,
-                                          pivot_value_new_text (N_("Error")));
+    int row = pivot_category_create_leaf (
+      source->root,
+      pivot_value_new_text_translate ("Error", C_("statistics", "Error")));
     const double df = n_total - df_corr;
     const double ssq = gsl_vector_get (ws->ssq, 0);
     const double mse = ssq / df;
index fff7f8d295b74ba85abf92b1f0ade4c3f0625f80..476842cb8fe1393b64cbb12c647303590cade93e 100644 (file)
@@ -2860,8 +2860,20 @@ pivot_value_new_user_text (const char *text, size_t length)
 struct pivot_value *
 pivot_value_new_text (const char *text)
 {
-  char *c = xstrdup (text);
-  char *local = xstrdup (gettext (c));
+  return pivot_value_new_text_translate (text, gettext (text));
+}
+
+/* Creates and returns new pivot_value whose original contents is
+   ORIG_TEXT and translated contents is TRANS_TEXT.
+   This function is for text strings that are part of the PSPP user
+   interface, such as names of procedures, statistics, annotations, error
+   messages, etc.  For strings that come from the user, use
+   pivot_value_new_user_text(). */
+struct pivot_value *
+pivot_value_new_text_translate (const char* orig_text, const char *trans_text)
+{
+  char *c = xstrdup (orig_text);
+  char *local = xstrdup (trans_text);
 
   struct pivot_value *value = xmalloc (sizeof *value);
   *value = (struct pivot_value) {
index 12e7d61f2f10f44898e21875096f9c75aaef93b3..13ad291743503c1bdbd1d2e868e04947f8dd7465 100644 (file)
@@ -817,6 +817,7 @@ struct pivot_value *pivot_value_new_variable__ (const char *name,
 
 /* Values from text strings. */
 struct pivot_value *pivot_value_new_text (const char *);
+struct pivot_value *pivot_value_new_text_translate (const char *, const char *);
 struct pivot_value *pivot_value_new_text_format (const char *, ...)
 #if defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__>= 4) || __GNUC__ > 4)
   __attribute__((format(gnu_printf, 1, 2)));