Hello,
I noticed that CSV account import table header had untranslatable text.
I made it translatable but ran into a problem with mnemonics ('_' needs
to be escaped as "__").
At first I tried to find a way to disable mnemonics in GtkTreeViewColumn
since they are not needed here at all.
Failing that I tried to find some glib utility function to escape the
string as needed. Failed to do that too.
Finally, I had to create a function mnemonic_escape  (like g_strescape)
to make it work.

Does anyone know a better solution?
>From 5d9b8a701f19c9065be11b7e7f360c4f0199d722 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Aurimas=20Fi=C5=A1eras?= <[email protected]>
Date: Sun, 7 Jul 2013 18:26:22 +0300
Subject: Make CSV account import table header translatable

---
 src/import-export/csv-export/csv-tree-export.c     |  4 +--
 .../csv-import/assistant-csv-account-import.c      | 37 ++++++++++++++++++++--
 2 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/src/import-export/csv-export/csv-tree-export.c b/src/import-export/csv-export/csv-tree-export.c
index ef71511..92a2850 100644
--- a/src/import-export/csv-export/csv-tree-export.c
+++ b/src/import-export/csv-export/csv-tree-export.c
@@ -109,11 +109,11 @@ void csv_tree_export (CsvExportInfo *info)
         }
 
         /* Header string */
-        header = g_strconcat ( end_sep, _("type"), mid_sep, _("fullname"), mid_sep,
+        header = g_strconcat ( end_sep, _("type"), mid_sep, _("full_name"), mid_sep,
                                _("name"), mid_sep, _("code"), mid_sep,
                                _("description"), mid_sep, _("color"), mid_sep, _("notes"), mid_sep,
                                _("commoditym"), mid_sep, _("commodityn"), mid_sep,
-                               _("hidden"), mid_sep, _("tax"), mid_sep, _("placeholder"), end_sep, "\n", NULL);
+                               _("hidden"), mid_sep, _("tax"), mid_sep, _("place_holder"), end_sep, "\n", NULL);
         DEBUG("Header String: %s", header);
 
         /* Write header line */
diff --git a/src/import-export/csv-import/assistant-csv-account-import.c b/src/import-export/csv-import/assistant-csv-account-import.c
index d073016..0066ba3 100644
--- a/src/import-export/csv-import/assistant-csv-account-import.c
+++ b/src/import-export/csv-import/assistant-csv-account-import.c
@@ -81,6 +81,37 @@ static const gchar *new_book_finish_tree_string = N_(
             "imported data are converted to GnuCash transactions. If this is an "
             "existing file, the dialog will not be shown.\n");
 
+/* Escape '_' in string */
+static gchar *mnemonic_escape (const gchar *source);
+static gchar *mnemonic_escape (const gchar *source)
+{
+    const guchar *p;
+    gchar *dest;
+    gchar *q;
+
+    g_return_val_if_fail (source != NULL, NULL);
+
+    p = (guchar *) source;
+    q = dest = g_malloc (strlen (source) * 2 + 1);
+
+    while (*p)
+      {
+        switch (*p)
+          {
+          case '_':
+            *q++ = '_';
+            *q++ = '_';
+            break;
+          default:
+            *q++ = *p;
+            break;
+          }
+        p++;
+      }
+    *q = 0;
+    return dest;
+}
+
 /*************************************************************************/
 
 /**************************************************
@@ -586,12 +617,12 @@ csv_import_assistant_create (CsvImportInfo *info)
     gtk_tree_view_set_model( GTK_TREE_VIEW(info->tree_view), GTK_TREE_MODEL(info->store) );
 #define CREATE_COLUMN(description,column_id) \
   renderer = gtk_cell_renderer_text_new (); \
-  column = gtk_tree_view_column_new_with_attributes (description, renderer, "text", column_id, NULL); \
+  column = gtk_tree_view_column_new_with_attributes (mnemonic_escape(_(description)), renderer, "text", column_id, NULL); \
   gtk_tree_view_column_add_attribute(column, renderer, "background", ROW_COLOR); \
   gtk_tree_view_column_set_resizable (column, TRUE); \
   gtk_tree_view_append_column (GTK_TREE_VIEW (info->tree_view), column);
     CREATE_COLUMN ("type", TYPE);
-    CREATE_COLUMN ("full__name", FULL_NAME);
+    CREATE_COLUMN ("full_name", FULL_NAME);
     CREATE_COLUMN ("name", NAME);
     CREATE_COLUMN ("code", CODE);
     CREATE_COLUMN ("description", DESCRIPTION);
@@ -601,7 +632,7 @@ csv_import_assistant_create (CsvImportInfo *info)
     CREATE_COLUMN ("commodityn", COMMODITYN);
     CREATE_COLUMN ("hidden", HIDDEN);
     CREATE_COLUMN ("tax", TAX);
-    CREATE_COLUMN ("place__holder", PLACE_HOLDER);
+    CREATE_COLUMN ("place_holder", PLACE_HOLDER);
 
     /* Finish Page */
     info->finish_label = GTK_WIDGET(gtk_builder_get_object(builder, "end_page"));
-- 
1.8.3.2

_______________________________________________
gnucash-devel mailing list
[email protected]
https://lists.gnucash.org/mailman/listinfo/gnucash-devel

Reply via email to