[gnumeric] GUI: Lay the foundation for translated function names.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] GUI: Lay the foundation for translated function names.
- Date: Wed, 30 Mar 2011 12:58:23 +0000 (UTC)
commit 51ac2d3f5e23d1e4fc45585e370d3542080a704e
Author: Morten Welinder <terra gnome org>
Date: Wed Mar 30 08:57:51 2011 -0400
GUI: Lay the foundation for translated function names.
ChangeLog | 8 ++++++++
plugins/excel/ms-excel-read.c | 2 +-
plugins/openoffice/openoffice-write.c | 2 +-
src/dialogs/dialog-formula-guru.c | 2 +-
src/dialogs/dialog-function-select.c | 26 ++++++++++++++++++--------
src/expr.c | 2 +-
src/func.c | 8 +++++---
src/func.h | 3 ++-
src/gnm-plugin.c | 2 +-
src/parse-util.c | 18 +++++++++++-------
src/parse-util.h | 3 +++
src/widgets/gnumeric-expr-entry.c | 31 +++++++++++++++++++++----------
12 files changed, 73 insertions(+), 34 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index dd3e708..0f00412 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2011-03-30 Morten Welinder <terra gnome org>
+
+ * src/parse-util.h (GnmConventions): Add field for localized
+ function names.
+
+ * src/func.c (gnm_func_get_name): Take extra argument indicating
+ whether the name should be localized. All callers changed.
+
2011-03-28 Morten Welinder <terra gnome org>
* src/stf-parse.c (dump_guessed_options): New function.
diff --git a/plugins/excel/ms-excel-read.c b/plugins/excel/ms-excel-read.c
index 7d4bfca..8a9fede 100644
--- a/plugins/excel/ms-excel-read.c
+++ b/plugins/excel/ms-excel-read.c
@@ -7083,7 +7083,7 @@ excel_read_init (void)
/* Fix case. */
if (func)
- name = gnm_func_get_name (func);
+ name = gnm_func_get_name (func, FALSE);
g_assert (g_hash_table_lookup (excel_func_by_name, name) ==
NULL);
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index 850c970..d5b7c73 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -2347,7 +2347,7 @@ odf_expr_func_handler (GnmConventionsOut *out, GnmExprFunction const *func)
static GHashTable *namemap = NULL;
static GHashTable *handlermap = NULL;
- char const *name = gnm_func_get_name (func->func);
+ char const *name = gnm_func_get_name (func->func, FALSE);
gboolean (*handler) (GnmConventionsOut *out, GnmExprFunction const *func);
if (NULL == namemap) {
diff --git a/src/dialogs/dialog-formula-guru.c b/src/dialogs/dialog-formula-guru.c
index 215a37f..e1f7f9c 100644
--- a/src/dialogs/dialog-formula-guru.c
+++ b/src/dialogs/dialog-formula-guru.c
@@ -155,7 +155,7 @@ dialog_formula_guru_update_this_parent (GtkTreeIter *parent, FormulaGuruState *s
g_return_if_fail (!is_non_fun);
g_return_if_fail (fd != NULL);
- text = g_string_append (text, gnm_func_get_name (fd));
+ text = g_string_append (text, gnm_func_get_name (fd, sheet_get_conventions (state->pos->sheet)->localized_function_names));
text = g_string_append (text, "(");
if (gtk_tree_model_iter_children (GTK_TREE_MODEL(state->model), &iter, parent)) {
diff --git a/src/dialogs/dialog-function-select.c b/src/dialogs/dialog-function-select.c
index 18d06b9..e5b7fe5 100644
--- a/src/dialogs/dialog-function-select.c
+++ b/src/dialogs/dialog-function-select.c
@@ -65,6 +65,8 @@ typedef struct {
Workbook *wb;
Sheet *sheet;
+ gboolean localized_function_names;
+
GtkBuilder *gui;
GtkWidget *dialog;
GtkWidget *ok_button;
@@ -292,7 +294,9 @@ dialog_function_write_recent_func (FunctionSelectState *state, GnmFunc const *fd
for (rec_funcs = state->recent_funcs; rec_funcs; rec_funcs = rec_funcs->next) {
gconf_value_list = g_slist_prepend
- (gconf_value_list, g_strdup (gnm_func_get_name (rec_funcs->data)));
+ (gconf_value_list,
+ g_strdup (gnm_func_get_name (rec_funcs->data,
+ state->localized_function_names)));
}
gnm_conf_set_functionselector_recentfunctions (gconf_value_list);
go_slist_free_custom (gconf_value_list, g_free);
@@ -440,12 +444,16 @@ cb_dialog_function_row_activated (GtkTreeView *tree_view,
}
static gint
-dialog_function_select_by_name (gconstpointer _a, gconstpointer _b)
+dialog_function_select_by_name (gconstpointer a_, gconstpointer b_,
+ gpointer user)
{
- GnmFunc const * const a = (GnmFunc const * const)_a;
- GnmFunc const * const b = (GnmFunc const * const)_b;
+ GnmFunc const * const a = (GnmFunc const * const)a_;
+ GnmFunc const * const b = (GnmFunc const * const)b_;
+ FunctionSelectState const *state = user;
+ gboolean localized = state->localized_function_names;
- return strcmp (gnm_func_get_name (a), gnm_func_get_name (b));
+ return g_utf8_collate (gnm_func_get_name (a, localized),
+ gnm_func_get_name (b, localized));
}
/*************************************************************************/
@@ -1105,8 +1113,9 @@ dialog_function_select_load_tree (FunctionSelectState *state)
funcs = g_slist_concat (funcs,
g_slist_copy (cat->functions));
- funcs = g_slist_sort (funcs,
- dialog_function_select_by_name);
+ funcs = g_slist_sort_with_data (funcs,
+ dialog_function_select_by_name,
+ state);
for (ptr = funcs; ptr; ptr = ptr->next) {
func = ptr->data;
@@ -1117,7 +1126,7 @@ dialog_function_select_load_tree (FunctionSelectState *state)
desc = dialog_function_select_get_description (func, &pal);
gtk_list_store_set
(state->model_functions, &iter,
- FUN_NAME, gnm_func_get_name (func),
+ FUN_NAME, gnm_func_get_name (func, state->localized_function_names),
FUNCTION, func,
FUNCTION_DESC, desc,
FUNCTION_PAL, pal,
@@ -1352,6 +1361,7 @@ dialog_function_select_full (WBCGtk *wbcg, char const *guru_key,
state = g_new (FunctionSelectState, 1);
state->wbcg = wbcg;
state->sheet = wb_control_cur_sheet (WORKBOOK_CONTROL (wbcg));
+ state->localized_function_names = state->sheet->convs->localized_function_names;
state->wb = state->sheet->workbook;
state->gui = gui;
state->dialog = go_gtk_builder_get_widget (state->gui, "selection_dialog");
diff --git a/src/expr.c b/src/expr.c
index 2fb2f15..15b0d65 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -2624,7 +2624,7 @@ gboolean
gnm_expr_is_data_table (GnmExpr const *expr, GnmCellPos *c_in, GnmCellPos *r_in)
{
if (GNM_EXPR_GET_OPER (expr) == GNM_EXPR_OP_FUNCALL) {
- char const *name = gnm_func_get_name (expr->func.func);
+ char const *name = gnm_func_get_name (expr->func.func, FALSE);
if (name && 0 == strcmp (name, "table")) {
if (NULL != r_in) {
GnmExpr const *r = (expr->func.argc <= 0)
diff --git a/src/func.c b/src/func.c
index a071049..31da915 100644
--- a/src/func.c
+++ b/src/func.c
@@ -53,7 +53,7 @@ functions_shutdown (void)
GnmFunc *func = unknown_cat->functions->data;
if (func->ref_count > 0) {
g_warning ("Function %s still has %d refs.\n",
- gnm_func_get_name (func),
+ gnm_func_get_name (func, FALSE),
func->ref_count);
func->ref_count = 0;
}
@@ -1193,11 +1193,13 @@ gnm_func_set_user_data (GnmFunc *func, gpointer user_data)
}
char const *
-gnm_func_get_name (GnmFunc const *func)
+gnm_func_get_name (GnmFunc const *func, gboolean localized_function_names)
{
g_return_val_if_fail (func != NULL, NULL);
- return func->name;
+ return localized_function_names
+ ? dgettext (func->textdomain->str, func->name)
+ : func->name;
}
/**
diff --git a/src/func.h b/src/func.h
index f45d3bc..a5ef56e 100644
--- a/src/func.h
+++ b/src/func.h
@@ -226,7 +226,8 @@ void gnm_func_ref (GnmFunc *func);
void gnm_func_unref (GnmFunc *func);
void gnm_func_load_if_stub (GnmFunc *func);
void gnm_func_load_stub (GnmFunc *fn_def);
-char const *gnm_func_get_name (GnmFunc const *fn_def);
+char const *gnm_func_get_name (GnmFunc const *fn_def,
+ gboolean localized);
gpointer gnm_func_get_user_data (GnmFunc const *func);
void gnm_func_set_user_data (GnmFunc *func, gpointer user_data);
GnmFunc *gnm_func_lookup (char const *name, Workbook *scope); /* change scope one day */
diff --git a/src/gnm-plugin.c b/src/gnm-plugin.c
index 71b2277..ec8ebb2 100644
--- a/src/gnm-plugin.c
+++ b/src/gnm-plugin.c
@@ -165,7 +165,7 @@ plugin_service_function_group_func_desc_load (GnmFunc const *fn_def,
return FALSE;
}
return sfg->cbs.func_desc_load (service,
- gnm_func_get_name (fn_def),
+ gnm_func_get_name (fn_def, FALSE),
res);
}
diff --git a/src/parse-util.c b/src/parse-util.c
index 26fcb7e..0af15fb 100644
--- a/src/parse-util.c
+++ b/src/parse-util.c
@@ -1153,13 +1153,13 @@ rangeref_parse (GnmRangeRef *res, char const *start, GnmParsePos const *pp,
static void
std_expr_func_handler (GnmConventionsOut *out, GnmExprFunction const *func)
{
- char const *name = gnm_func_get_name (func->func);
- GString *target = out->accum;
+ char const *name = gnm_func_get_name (func->func,
+ out->convs->localized_function_names);
+ GString *target = out->accum;
- g_string_append (target, name);
- /* FIXME: possibly a space here. */
- gnm_expr_list_as_string (func->argc, func->argv, out);
- return;
+ g_string_append (target, name);
+ /* FIXME: possibly a space here. */
+ gnm_expr_list_as_string (func->argc, func->argv, out);
}
static void
@@ -1170,7 +1170,8 @@ std_expr_name_handler (GnmConventionsOut *out, GnmExprName const *name)
if (!thename->active) {
g_string_append (target,
- value_error_name (GNM_ERROR_REF, out->convs->output.translated));
+ value_error_name (GNM_ERROR_REF,
+ out->convs->output.translated));
return;
}
@@ -1351,6 +1352,9 @@ gnm_conventions_new_full (unsigned size)
convs = g_malloc0 (size);
convs->ref_count = 1;
+ convs->r1c1_addresses = FALSE;
+ convs->localized_function_names = FALSE;
+
convs->sheet_name_sep = '!';
convs->intersection_char = ' ';
convs->exp_is_left_associative = FALSE;
diff --git a/src/parse-util.h b/src/parse-util.h
index d37cbcb..7270e07 100644
--- a/src/parse-util.h
+++ b/src/parse-util.h
@@ -105,6 +105,9 @@ struct _GnmConventions {
#endif
gboolean r1c1_addresses;
+ /* Whether function names should be translated. */
+ gboolean localized_function_names;
+
/* Separate elements in lists, 0 will use go_locale. */
gunichar arg_sep;
/* Separate array columns, 0 will use go_locale. */
diff --git a/src/widgets/gnumeric-expr-entry.c b/src/widgets/gnumeric-expr-entry.c
index d89fc32..6b63a19 100644
--- a/src/widgets/gnumeric-expr-entry.c
+++ b/src/widgets/gnumeric-expr-entry.c
@@ -728,6 +728,8 @@ gee_set_tooltip (GnmExprEntry *gee, GnmFunc *fd, gint args, gboolean had_stuff)
gint min, max, i;
gboolean first = TRUE;
char *extra = NULL;
+ gboolean localized_function_names = gee->sheet->convs->localized_function_names;
+ const char *fdname;
gnm_func_load_if_stub (fd);
function_def_count_args (fd, &min, &max);
@@ -741,7 +743,9 @@ gee_set_tooltip (GnmExprEntry *gee, GnmFunc *fd, gint args, gboolean had_stuff)
gee->tooltip.fd = fd;
gnm_func_ref (gee->tooltip.fd);
- str = g_string_new (gnm_func_get_name (fd));
+ fdname = gnm_func_get_name (fd, localized_function_names);
+
+ str = g_string_new (fdname);
g_string_append_c (str, '(');
for (i = 0; i < max; i++) {
@@ -776,11 +780,11 @@ gee_set_tooltip (GnmExprEntry *gee, GnmFunc *fd, gint args, gboolean had_stuff)
}
if (max == 0 && args == 0 && !had_stuff) {
extra = g_strdup_printf (_("%s takes no arguments"),
- gnm_func_get_name (fd));
+ fdname);
} else if (args >= max) {
g_string_append (str, UNICODE_RIGHT_TRIANGLE UNICODE_CROSS_AND_SKULLBONES UNICODE_LEFT_TRIANGLE);
extra = g_strdup_printf (_("Too many arguments for %s"),
- gnm_func_get_name (fd));
+ fdname);
}
g_string_append_c (str, ')');
if (extra) {
@@ -807,13 +811,14 @@ gee_set_tooltip_completion (GnmExprEntry *gee, GSList *list, guint start, guint
GSList *list_c = list;
gchar const *name = NULL;
gboolean show_tool_tip;
+ gboolean localized_function_names = gee->sheet->convs->localized_function_names;
gee_delete_tooltip (gee, TRUE);
str = g_string_new (NULL);
for (; list_c != NULL && ++i < max; list_c = list_c->next) {
GnmFunc *fd = list_c->data;
- name = gnm_func_get_name (fd);
+ name = gnm_func_get_name (fd, localized_function_names);
if ((end - start) < (guint) g_utf8_strlen (name, -1))
/* xgettext: the first %s is a function name and */
/* the second %s the function description */
@@ -865,11 +870,16 @@ gee_dump_lexer (GnmLexerItem *gli) {
}
-static int
-func_def_cmp (gconstpointer a, gconstpointer b)
+static gint
+func_def_cmp (gconstpointer a_, gconstpointer b_, gpointer user)
{
- return g_utf8_collate (gnm_func_get_name (a),
- gnm_func_get_name (b));
+ GnmFunc const * const a = (GnmFunc const * const)a_;
+ GnmFunc const * const b = (GnmFunc const * const)b_;
+ GnmExprEntry *gee = user;
+ gboolean localized = gee->sheet->convs->localized_function_names;
+
+ return g_utf8_collate (gnm_func_get_name (a, localized),
+ gnm_func_get_name (b, localized));
}
@@ -991,9 +1001,10 @@ gee_check_tooltip (GnmExprEntry *gee)
(prefix, gee->sheet->workbook);
g_free (prefix);
if (list != NULL) {
- list = g_slist_sort
+ list = g_slist_sort_with_data
(list,
- (GCompareFunc)func_def_cmp);
+ func_def_cmp,
+ gee);
if (gee_set_tooltip_completion
(gee, list, start_t, end_t)) {
g_free (str);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]