[gnumeric] GnmFunc: centralize function text translations.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] GnmFunc: centralize function text translations.
- Date: Sat, 26 May 2018 02:11:29 +0000 (UTC)
commit e83e794609ab7064240c4a6640441f4a76d9e25d
Author: Morten Welinder <terra gnome org>
Date: Fri May 25 20:19:47 2018 -0400
GnmFunc: centralize function text translations.
src/dialogs/dialog-formula-guru.c | 3 +-
src/dialogs/dialog-function-select.c | 18 +++++------
src/func.c | 60 +++++++++++++++++++++++-------------
src/func.h | 6 ++--
src/sstest.c | 19 ++++++------
5 files changed, 59 insertions(+), 47 deletions(-)
---
diff --git a/src/dialogs/dialog-formula-guru.c b/src/dialogs/dialog-formula-guru.c
index a10b71b74..b80ceb153 100644
--- a/src/dialogs/dialog-formula-guru.c
+++ b/src/dialogs/dialog-formula-guru.c
@@ -269,7 +269,7 @@ dialog_formula_guru_update_this_child (GtkTreeIter *child, FormulaGuruState *sta
static void
-dialog_formula_guru_adjust_children (GtkTreeIter *parent, GnmFunc const *fd,
+dialog_formula_guru_adjust_children (GtkTreeIter *parent, GnmFunc *fd,
FormulaGuruState *state)
{
gboolean is_non_fun;
@@ -277,7 +277,6 @@ dialog_formula_guru_adjust_children (GtkTreeIter *parent, GnmFunc const *fd,
gint min_arg, max_arg, args = 0, i;
char *arg_name;
-
if (fd == NULL) {
gtk_tree_model_get (GTK_TREE_MODEL(state->model), parent,
IS_NON_FUN, &is_non_fun,
diff --git a/src/dialogs/dialog-function-select.c b/src/dialogs/dialog-function-select.c
index ae0f8338b..3d5fe254f 100644
--- a/src/dialogs/dialog-function-select.c
+++ b/src/dialogs/dialog-function-select.c
@@ -44,8 +44,6 @@
#include <gsf/gsf-impl-utils.h>
#include <string.h>
-#define F2(func,s) dgettext (gnm_func_get_translation_domain(func), (s))
-
#define FUNCTION_SELECT_KEY "function-selector-dialog"
#define FUNCTION_SELECT_HELP_KEY "function-selector-dialog-help-mode"
#define FUNCTION_SELECT_PASTE_KEY "function-selector-dialog-paste-mode"
@@ -747,7 +745,7 @@ describe_new_style (GtkTextBuffer *description,
for (help = func->help; 1; help++) {
switch (help->type) {
case GNM_FUNC_HELP_NAME: {
- const char *text = F2 (func, help->text);
+ const char *text = gnm_func_gettext (func, help->text);
const char *colon = strchr (text, ':');
if (!colon)
break;
@@ -758,7 +756,7 @@ describe_new_style (GtkTextBuffer *description,
break;
}
case GNM_FUNC_HELP_ARG: {
- const char *text = F2 (func, help->text);
+ const char *text = gnm_func_gettext (func, help->text);
const char *colon = strchr (text, ':');
if (!colon)
break;
@@ -776,7 +774,7 @@ describe_new_style (GtkTextBuffer *description,
break;
}
case GNM_FUNC_HELP_DESCRIPTION: {
- const char *text = F2 (func, help->text);
+ const char *text = gnm_func_gettext (func, help->text);
FINISH_ARGS;
ADD_TEXT ("\n");
ADD_TEXT_WITH_ARGS (text);
@@ -784,7 +782,7 @@ describe_new_style (GtkTextBuffer *description,
break;
}
case GNM_FUNC_HELP_NOTE: {
- const char *text = F2 (func, help->text);
+ const char *text = gnm_func_gettext (func, help->text);
FINISH_ARGS;
ADD_TEXT ("\n");
ADD_TEXT (_("Note: "));
@@ -793,7 +791,7 @@ describe_new_style (GtkTextBuffer *description,
break;
}
case GNM_FUNC_HELP_EXAMPLES: {
- const char *text = F2 (func, help->text);
+ const char *text = gnm_func_gettext (func, help->text);
gboolean was_translated = (text != help->text);
FINISH_ARGS;
@@ -880,7 +878,7 @@ describe_new_style (GtkTextBuffer *description,
break;
}
case GNM_FUNC_HELP_EXCEL: {
- const char *text = F2 (func, help->text);
+ const char *text = gnm_func_gettext (func, help->text);
FINISH_ARGS;
ADD_TEXT ("\n");
ADD_TEXT (_("Microsoft Excel: "));
@@ -889,7 +887,7 @@ describe_new_style (GtkTextBuffer *description,
break;
}
case GNM_FUNC_HELP_ODF: {
- const char *text = F2 (func, help->text);
+ const char *text = gnm_func_gettext (func, help->text);
FINISH_ARGS;
ADD_TEXT ("\n");
ADD_TEXT (_("ODF (OpenFormula): "));
@@ -1106,7 +1104,7 @@ dialog_function_select_peek_description (GnmFunc *func)
default:
break;
case GNM_FUNC_HELP_NAME: {
- const char *text = F2 (func, help->text);
+ const char *text = gnm_func_gettext (func, help->text);
const char *colon = strchr (text, ':');
return (colon ? colon + 1 : text);
}
diff --git a/src/func.c b/src/func.c
index 5eea7afa9..3f1feba5c 100644
--- a/src/func.c
+++ b/src/func.c
@@ -52,8 +52,6 @@ enum {
static guint signals[LAST_SIGNAL] = { 0 };
-#define F2(func,s) dgettext ((func)->tdomain->str, (s))
-
static GList *categories;
static GnmFuncGroup *unknown_cat;
@@ -295,12 +293,12 @@ gnm_func_create_arg_names (GnmFunc *fn_def)
for (i = 0;
fn_def->help && fn_def->help[i].type != GNM_FUNC_HELP_END;
i++) {
+ const char *s;
if (fn_def->help[i].type != GNM_FUNC_HELP_ARG)
continue;
- g_ptr_array_add
- (ptr, split_at_colon
- (F2(fn_def, fn_def->help[i].text), NULL));
+ s = gnm_func_gettext (fn_def, fn_def->help[i].text);
+ g_ptr_array_add (ptr, split_at_colon (s, NULL));
}
fn_def->arg_names = ptr;
@@ -577,6 +575,24 @@ gnm_func_set_translation_domain (GnmFunc *func, const char *tdomain)
g_object_notify (G_OBJECT (func), "translation-domain");
}
+/**
+ * gnm_func_gettext:
+ * @func: #GnmFunc
+ * @str: string to translate
+ *
+ * Returns: (transfer none): @str translated in the relevant translation
+ * domain.
+ */
+char const *
+gnm_func_gettext (GnmFunc *func, const char *str)
+{
+ g_return_val_if_fail (GNM_IS_FUNC (func), NULL);
+ g_return_val_if_fail (str != NULL, NULL);
+
+ return dgettext ((func)->tdomain->str, str);
+}
+
+
GnmFuncFlags
gnm_func_get_flags (GnmFunc *func)
{
@@ -911,11 +927,11 @@ gnm_func_get_name (GnmFunc const *func, gboolean localized)
continue;
s = func->help[i].text;
- sl = F2 (func, s);
+ sl = gnm_func_gettext (fd, s);
if (s == sl) /* String not actually translated. */
continue;
- U = split_at_colon (F2 (func, s), NULL);
+ U = split_at_colon (sl, NULL);
if (U) {
char *lname = g_utf8_strdown (U, -1);
gnm_func_set_localized_name (fd, lname);
@@ -932,27 +948,27 @@ gnm_func_get_name (GnmFunc const *func, gboolean localized)
/**
* gnm_func_get_description:
- * @fn_def: the fn defintion
+ * @func: #GnmFunc
*
* Returns: (transfer none): the description of the function
**/
char const *
-gnm_func_get_description (GnmFunc const *fn_def)
+gnm_func_get_description (GnmFunc *func)
{
gint i;
- g_return_val_if_fail (fn_def != NULL, NULL);
+ g_return_val_if_fail (func != NULL, NULL);
- gnm_func_load_if_stub ((GnmFunc *)fn_def);
+ gnm_func_load_if_stub (func);
for (i = 0;
- fn_def->help && fn_def->help[i].type != GNM_FUNC_HELP_END;
+ func->help && func->help[i].type != GNM_FUNC_HELP_END;
i++) {
const char *desc;
- if (fn_def->help[i].type != GNM_FUNC_HELP_NAME)
+ if (func->help[i].type != GNM_FUNC_HELP_NAME)
continue;
- desc = strchr (F2 (fn_def, fn_def->help[i].text), ':');
+ desc = strchr (gnm_func_gettext (func, func->help[i].text), ':');
return desc ? (desc + 1) : "";
}
return "";
@@ -1056,30 +1072,30 @@ gnm_func_get_arg_name (GnmFunc const *func, guint arg_idx)
/**
* gnm_func_get_arg_description:
- * @fn_def: the fn defintion
+ * @func: the fn defintion
* @arg_idx: zero-based argument offset
*
* Returns: (transfer none): the description of the argument
**/
-char const*
-gnm_func_get_arg_description (GnmFunc const *fn_def, guint arg_idx)
+char const *
+gnm_func_get_arg_description (GnmFunc *func, guint arg_idx)
{
gint i;
- g_return_val_if_fail (fn_def != NULL, NULL);
+ g_return_val_if_fail (func != NULL, NULL);
- gnm_func_load_if_stub ((GnmFunc *)fn_def);
+ gnm_func_load_if_stub (func);
for (i = 0;
- fn_def->help && fn_def->help[i].type != GNM_FUNC_HELP_END;
+ func->help && func->help[i].type != GNM_FUNC_HELP_END;
i++) {
gchar const *desc;
- if (fn_def->help[i].type != GNM_FUNC_HELP_ARG)
+ if (func->help[i].type != GNM_FUNC_HELP_ARG)
continue;
if (arg_idx--)
continue;
- desc = strchr (F2 (fn_def, fn_def->help[i].text), ':');
+ desc = strchr (gnm_func_gettext (func, func->help[i].text), ':');
if (!desc)
return "";
diff --git a/src/func.h b/src/func.h
index cd612bed6..bd15214b7 100644
--- a/src/func.h
+++ b/src/func.h
@@ -226,6 +226,7 @@ gboolean gnm_func_get_in_use (GnmFunc *func);
char const *gnm_func_get_translation_domain (GnmFunc *func);
void gnm_func_set_translation_domain (GnmFunc *func,
const char *tdomain);
+char const *gnm_func_gettext (GnmFunc *func, const char *str);
GnmFuncFlags gnm_func_get_flags (GnmFunc *func);
void gnm_func_set_flags (GnmFunc *func, GnmFuncFlags f);
@@ -268,7 +269,7 @@ GnmFunc *gnm_func_add_placeholder_localized (char const *gname, char const *l
GnmFunc *gnm_func_lookup_or_add_placeholder (char const *name);
/* TODO */
-char const *gnm_func_get_description (GnmFunc const *fn_def);
+char const *gnm_func_get_description (GnmFunc *func);
void gnm_func_count_args (GnmFunc const *fn_def,
gint *min, int *max);
char gnm_func_get_arg_type (GnmFunc const *fn_def,
@@ -276,8 +277,7 @@ char gnm_func_get_arg_type (GnmFunc const *fn_def,
char const *gnm_func_get_arg_type_string (GnmFunc const *fn_def,
gint arg_idx);
char *gnm_func_get_arg_name (GnmFunc const *func, guint arg_idx);
-char const *gnm_func_get_arg_description (GnmFunc const *fn_def,
- guint arg_idx);
+char const *gnm_func_get_arg_description (GnmFunc *func, guint arg_idx);
char *gnm_func_convert_markup_to_pango (char const *desc,
GtkWidget *target);
diff --git a/src/sstest.c b/src/sstest.c
index 99a9cc45a..741918ba0 100644
--- a/src/sstest.c
+++ b/src/sstest.c
@@ -92,7 +92,6 @@ static GOptionEntry const sstest_options [] = {
/* ------------------------------------------------------------------------- */
#define UNICODE_ELLIPSIS "\xe2\x80\xa6"
-#define F2(func,s) dgettext (gnm_func_get_translation_domain(func), (s))
static char *
split_at_colon (char const *s, char **rest)
@@ -129,7 +128,7 @@ dump_externals (GPtrArray *defs, FILE *out)
int j;
for (j = 0; fd->help[j].type != GNM_FUNC_HELP_END; j++) {
- const char *s = F2(fd, fd->help[j].text);
+ const char *s = gnm_func_gettext (fd, fd->help[j].text);
switch (fd->help[j].type) {
case GNM_FUNC_HELP_EXTREF:
@@ -449,14 +448,14 @@ function_dump_defs (char const *filename, int dump_type)
GnmFuncGroup *group = gnm_func_get_function_group (fd);
fprintf (output_file, "@CATEGORY=%s\n",
- F2(fd, group->display_name->str));
+ gnm_func_gettext (fd, group->display_name->str));
for (i = 0;
fd->help[i].type != GNM_FUNC_HELP_END;
i++) {
switch (fd->help[i].type) {
case GNM_FUNC_HELP_NAME: {
char *short_desc;
- char *name = split_at_colon (F2(fd, fd->help[i].text), &short_desc);
+ char *name = split_at_colon (gnm_func_gettext (fd, fd->help[i].text),
&short_desc);
fprintf (output_file,
"@FUNCTION=%s\n",
name);
@@ -471,21 +470,21 @@ function_dump_defs (char const *filename, int dump_type)
case GNM_FUNC_HELP_SEEALSO:
if (seealso->len > 0)
g_string_append (seealso, ",");
- g_string_append (seealso, F2(fd, fd->help[i].text));
+ g_string_append (seealso, gnm_func_gettext (fd, fd->help[i].text));
break;
case GNM_FUNC_HELP_DESCRIPTION:
if (desc->len > 0)
g_string_append (desc, "\n");
- g_string_append (desc, F2(fd, fd->help[i].text));
+ g_string_append (desc, gnm_func_gettext (fd, fd->help[i].text));
break;
case GNM_FUNC_HELP_NOTE:
if (note->len > 0)
g_string_append (note, " ");
- g_string_append (note, F2(fd, fd->help[i].text));
+ g_string_append (note, gnm_func_gettext (fd, fd->help[i].text));
break;
case GNM_FUNC_HELP_ARG: {
char *argdesc;
- char *name = split_at_colon (F2(fd, fd->help[i].text), &argdesc);
+ char *name = split_at_colon (gnm_func_gettext (fd, fd->help[i].text),
&argdesc);
if (first_arg)
first_arg = FALSE;
else
@@ -504,12 +503,12 @@ function_dump_defs (char const *filename, int dump_type)
case GNM_FUNC_HELP_ODF:
if (odf->len > 0)
g_string_append (odf, " ");
- g_string_append (odf, F2(fd, fd->help[i].text));
+ g_string_append (odf, gnm_func_gettext (fd, fd->help[i].text));
break;
case GNM_FUNC_HELP_EXCEL:
if (excel->len > 0)
g_string_append (excel, " ");
- g_string_append (excel, F2(fd, fd->help[i].text));
+ g_string_append (excel, gnm_func_gettext (fd, fd->help[i].text));
break;
case GNM_FUNC_HELP_EXTREF:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]