Commit 51ac2d3f authored by Morten Welinder's avatar Morten Welinder

GUI: Lay the foundation for translated function names.

parent 26adfbca
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.
......
......@@ -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);
......
......@@ -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) {
......
......@@ -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)) {
......
......@@ -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");
......
......@@ -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)
......
......@@ -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;
}
/**
......
......@@ -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 */
......
......@@ -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);
}
......
......@@ -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;
......
......@@ -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. */
......
......@@ -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);
......
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