Commit e83e7946 authored by Morten Welinder's avatar Morten Welinder

GnmFunc: centralize function text translations.

parent e9075ebc
......@@ -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,
......
......@@ -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);
}
......
......@@ -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 "";
......
......@@ -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);
......
......@@ -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:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment