[PyQt] i18n & combo box

Frédéric frederic.mantegazza at gbiloba.org
Sat Feb 14 11:25:18 GMT 2009


On vendredi 13 février 2009, Frédéric wrote:

> I have a little issue with i18n and combobox. I have a config dialog
> with some combobox, to allow the user to choose some pre-defined values.
> For example, the possible entries of one of my combobox are:
>
>     up
>     down
>     left
>     right
>
> which are translated, in french, by:
>
>     haut
>     bas
>     gauche
>     droite
>
> I store the user choice string in the config. file (based on the
> standard ConfigParser module). But when I setup the combobox, to
> pre-select the default choice (when the application is started the first
> time), I get nothing, because strings do not match! Here is my code:
>
> orientationComboBox.setCurrentIndex(self._view.orientationComboBox.findT
>ext(self._model.headOrientation))
>
> and to store back the value from teh combobox:
>
> self._model.headOrientation =
> str(self._view.orientationComboBox.currentText())
>
> With PyGTK, all was working fine; internal used strings where the
> original ones, not translated ones. Is there a way to have the same
> behaviour under PyQt?
>
> Thanks,
>
> PS: I don't want the translated  strings stored in the config. file,
> because it will lead to problems if the user change the locale, or if
> they ask for some help.

Ok, I finally found a solution, using a double entry index table, and using 
only index-related widgets methods. Example:

HEAD_ORIENTATION_INDEX = {'up': 0, 'left': 1, 'right': 2, 'down': 3,
                          0: 'up', 1: 'left', 2: 'right', 3: 'down'}

-- 
    Frédéric

    http://www.gbiloba.org



More information about the PyQt mailing list