Bug 3310 - Toolbar action buttons wrongly refer to translated action names
Summary: Toolbar action buttons wrongly refer to translated action names
Status: REOPENED
Alias: None
Product: Claws Mail (GTK 2)
Classification: Unclassified
Component: UI/Actions (show other bugs)
Version: other
Hardware: PC Linux
: P3 normal
Assignee: users
URL:
Depends on:
Blocks:
 
Reported: 2014-10-25 18:34 UTC by Albert ARIBAUD
Modified: 2014-11-07 21:01 UTC (History)
0 users

See Also:


Attachments

Description Albert ARIBAUD 2014-10-25 18:34:04 UTC
Steps to reproduce:

0. Run Claws Mail in French

1. Open Configuration / Actions.
   Add an action called "Ham" which uses an action filter to
   color a message in green, and an action called "Spam" which
   uses an action filter to color a message in red.
   Click "Valider".
   Select a message and check that the Tools/Action menu entries
   for "Ham" and "Spam" work as expected.

2. Open Configuration / Préferences... then Barre d'outils / Vue
   principale.
   Add one button for "Ham" and one for "Spam".
   Click "Valider".
   Check that the buttons' texts were translated from "Ham" to "Légitime"
   and from "Spam" to "Pourriel".
   Select a message and check that the buttons work as expected.

3. Go back to Configuration / Actions.
   Do NOT change anything, just click "Valider".
   Check that the buttons have DISAPPEARED.

4. Re-run steps 1-3 but with actions named "Légitime" and "Pourriel"
   instead of "Ham" and "Spam".
   Check that the buttons do NOT disappear at step 3.

=> Action-bound buttons refer to their actions through their translated
   names. Action-bound buttons should always refer to the actions'
   original names except for display purposes.
Comment 1 Albert ARIBAUD 2014-10-25 18:35:55 UTC
Correction to step #2:

   ...
   Select a message and check that the buttons DO NOT work as expected.

(buttons call their actions by their translated names, thus having no
effect, not even an error message saying there is no action called
"Légitime" or "Pourriel".
Comment 2 Paul 2014-10-26 17:03:04 UTC
I've followed your instructions as closely as I can, trying more than one variation, and it works fine for me.

You seem to be confusing user defined Actions with the built-in 'Learn spam or ham'.

Perhaps your instructions lack some vital information. For instance, in the Toolbars configuration you do not say which 'Item type' you are selecting, or the 'Event executed on click' option, not the 'Toolbar text' you have used.
Comment 3 Albert ARIBAUD 2014-10-26 17:52:59 UTC
@Paul (comment 2):

Did you run the CM in French when you tried to reproduce the issue?

I made sure the bug reproduction instructions worked, by trying them step by step as I was writing them. I can do a video capture of the screen and attach it to the bug report if that can help.

Indeed, I did discover the bug with spam filtering actions; but I did reproduce it with simple coloring actions, and I kept the names Ham and Spam because I knew these names would be translated and would thus trigger the bug.

As far as details are concerned: for both buttons item types was "Action" -- that is in fact the only item type you can select if you want to map a button to a user-defined action; and the item selected was the corresponding user defined action of course -- actually, I did not describt this phase as there can only be one way to create a
Comment 4 Albert ARIBAUD 2014-10-26 17:53:40 UTC
(sorry for the mistyping) ... to create a button mapped to a user-defined action
Comment 5 Albert ARIBAUD 2014-11-07 21:01:18 UTC
Further analysis shows that:
- in toolbar_main.xml, the added "Spam" button is represented as follows:

    <item file="mail_receive_all" text="Spam" action="A_CLAWS_ACTION"/>

This XML fragment is read in src/toolbar.c, whose line 370 copies the 'text'
attribute into a ToolbarItem's text field:

    item->text = g_strdup (*value ? gettext(value):"");

After this line, item->text equals "Pourriel" -- and the "Red" is lost.

Later on, when creating the ToolbarClawsActions struct, the action name is copied from the (translated) item's text field.

Later yet, prefs_actions_find_by_name() is called with the action's (translated) name -- and since no action "Pourriel" exists, none is taken.

A solution would be to store the untranslated action name in the gchar* 'text' field to the ToolbarItem and to only translate it when building the actual toolbar button.

I did try the following diff, which made the button work as expected.

@@ -367,7 +367,7 @@ static void toolbar_parse_item(XMLFile *file, ToolbarType source)
                if (g_utf8_collate(name, TOOLBAR_ICON_FILE) == 0) 
                        item->file = g_strdup (value);
                else if (g_utf8_collate(name, TOOLBAR_ICON_TEXT) == 0)
-                       item->text = g_strdup (*value ? gettext(value):"");
+                       item->text = g_strdup (value);
                else if (g_utf8_collate(name, TOOLBAR_ICON_ACTION) == 0)
                        item->index = toolbar_ret_val_from_text(value);
                if (item->index == -1 && !strcmp(value, "A_DELETE")) {
@@ -2150,7 +2150,7 @@ Toolbar *toolbar_create(ToolbarType        type,
 #endif
 
                case A_CLAWS_ACTIONS:
-                       TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,toolbar_item->text);
+                       TOOLBAR_ITEM(item,icon_wid,gettext(toolbar_item->text),toolbar_item->text);
                        action_item = g_new0(ToolbarClawsActions, 1);
                        action_item->widget = item;
                        action_item->name   = g_strdup(toolbar_item->text);

Of course, this is not a viable patch, only a proof of analysis.

Note You need to log in before you can comment on or make changes to this bug.