i18n and Combo widget?



I am trying to decide on the best way of implementing an
internationalized combo box. The obvious solution is to do the
following:

GtkWidget *combo;
const gchar *entry[] = {"foo", "bar"};
GList *items = NULL;

for (i = 0; i < 2 ++ i) {
   /* here _(text) is gettext(text) */
   items = g_list_append (items, _(entry[i]));
}

combo = gtk_combo_new ();
gtk_combo_set_popdown_strings (GTK_COMBO (combo), items);

The trouble is reacting to the "change" signal posted by the combo's
entry (the combo's entry is not editable, so I know I will get one of
the translated entries). In my case I would like to use the text of the
entry to look up stuff in GHashTable. But I can't, since it is
internationalized, while the hash table is build of plain entries (for
now, let us assume that this has to be this way). So the only way around
it is for me to store the "reverse" translation in another hash table.
Then I can do the following:

const gchar *text;
const gchar *txet

/* get the current content of the entry */
text = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (combo)->entry));

/* reverse translate the entry from i18n to original */
*txet = (const gchar *) g_hash_table_lookup (reverse, text);

/* use the reverse translated entry to lookup stuff ... */
stuff = g_hash_table_lookup (table, *txet);

But this seems to be wasteful. Since I am sure I am not the only one who
had to present internationalized text in combo box I was wondering if
people know of better solution? Any suggestions are greatly appreciated.

Bo



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]