From: Theppitak Karoonboonyanan Date: Fri, 11 Oct 2024 09:46:06 +0000 (+0700) Subject: Add translation context for statistical "Error" X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=69359d97371b41c19f1ff1b8f1fef2e215cc4f24;p=pspp Add translation context for statistical "Error" 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. --- diff --git a/po/automake.mk b/po/automake.mk index 163ec80f23..58c6ff8c6c 100644 --- a/po/automake.mk +++ b/po/automake.mk @@ -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 diff --git a/src/language/commands/glm.c b/src/language/commands/glm.c index 05ab9bf9ca..077fecc528 100644 --- a/src/language/commands/glm.c +++ b/src/language/commands/glm.c @@ -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; diff --git a/src/output/pivot-table.c b/src/output/pivot-table.c index fff7f8d295..476842cb8f 100644 --- a/src/output/pivot-table.c +++ b/src/output/pivot-table.c @@ -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) { diff --git a/src/output/pivot-table.h b/src/output/pivot-table.h index 12e7d61f2f..13ad291743 100644 --- a/src/output/pivot-table.h +++ b/src/output/pivot-table.h @@ -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)));