[PATCH] qt-language-selector crashes during startup in certain locales

Bug #266971 reported by M. Vefa Bicakci
62
Affects Status Importance Assigned to Milestone
language-selector (Ubuntu)
Fix Released
Undecided
Jonathan Riddell

Bug Description

Binary package hint: language-selector-qt

Hello,

I am a Turkish user of Ubuntu Hardy and I have noticed that
qt-language-selector does not start in the Turkish locale.
Here are what I found out and a fix for this problem.

qt-language-selector crashes when it is started in locales that
do not have translations for certain locales whose names contain
UTF-8 characters. This happens because if the locale names with
the mentioned characteristics do not have translations, they are not
defined as UTF-8 strings and hence cause problems when one tries
to operate on them. (Such as trying to sort them.)

There are two ways to reproduce this problem:

1) Switch your default locale to Turkish and reboot.
   Then start qt-language-selector. (Please note that
   you will be unable to change your default locale using
   qt-language-selector afterwards unless you apply the
   attached patch.)

2) [The safer method] Modify

   /usr/share/locale/"your locale name"/LC_MESSAGES/iso_639.mo

   using msgunfmt and msgfmt so that the following locale name
   translation is removed from that file:
 msgid "Norwegian Bokmål; Bokmål, Norwegian"

Since the second way is safer, I will demonstrate that one.
Steps to reproduce are as follows:

(I am assuming that you are using the German locale.)

==================================================
$ sudo su -
# cd /usr/share/locale/de/LC_MESSAGES
# cp iso_639.mo iso_639.orig.mo
# msgunfmt iso_639.mo > iso_639.txt
# nano iso_639.txt

### Remove the following two lines from that file:
### msgid "Norwegian Bokmål; Bokmål, Norwegian"
### msgstr "Buch-Norwegisch"

# msgfmt -o iso_639.mo iso_639.txt
# exit
$ sudo qt-language-selector --mode select

### Realize that qt-language-selector crashes...
==================================================

Here is the trace of the crash of qt-language-selector
after these steps have been carried out. This is
what is seen in locales that do not have translations
for that Norwegian locale name. To be specific, this
applies to the Turkish locale too.

==================================================
Traceback (most recent call last):
  File "/usr/bin/qt-language-selector", line 29, in <module>
    lc = QtLanguageSelector(app, "/usr/share/language-selector/", sys.argv[2])
  File "/usr/lib/python2.5/site-packages/LanguageSelector/qt/QtLanguageSelector.py", line 43, in __init__
    self.init()
  File "/usr/lib/python2.5/site-packages/LanguageSelector/qt/QtLanguageSelector.py", line 77, in init
    self.updateLanguagesList()
  File "/usr/lib/python2.5/site-packages/LanguageSelector/qt/QtLanguageSelector.py", line 120, in updateLanguagesList
    languages.sort()
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 3: ordinal not in range(128)
==================================================

This happens because the locale names that haven't been processed by
gettext are stored as regular ASCII labels in QtLanguageSelector.
Here is an excerpt from
"/usr/share/pyshared/LanguageSelector/qt/QtLanguageSelector.py"

==================================================
116 self._localeinfo.listviewStrToLangInfoMap = {}
117 for lang in languageList:
118 self._localeinfo.listviewStrToLangInfoMap[lang.language] = lang
119 languages = self._localeinfo.listviewStrToLangInfoMap.keys()
120 languages.sort()
==================================================

As you can see on line 118, the locale name ("lang.language") is
utilized as a regular ASCII string for a key of the dictionary even
though it may contain UTF-8 characters. This causes problems when
".sort()" is called on the keys on line 120 if some keys contain
UTF-8 characters.

The inspiration for the fix of this problem comes from the following
lines in "/usr/share/pyshared/LanguageSelector/qt/QtLanguageSelector.py":

==================================================
 99 for locale in self._localeinfo.generated_locales():
100 name = utf8(self._localeinfo.translate(locale))
101 locales.append(name)
102 self._localeinfo.localeToCodeMap[name] = locale
==================================================

As you can see, the "utf8()" function was used in line 100.
Hence, the fix for the mentioned bug also uses the "utf8()" function.

Attached is the patch which fixes this bug.

Regards,

M. Vefa Bicakci

Revision history for this message
M. Vefa Bicakci (mvb) wrote :
Revision history for this message
David Gaarenstroom (david-gaarenstroom) wrote :

I actually came up with the same patch, not knowing about this bug ID until using the "harvest" webapp (see bug #272405).

Changed in language-selector:
status: New → Confirmed
Revision history for this message
Arne Goetje (arnegoetje) wrote :

Thanks for the patch. Does the same issue happen also with gnome-language-selector?

Revision history for this message
David Gaarenstroom (david-gaarenstroom) wrote :

I guess if it does, there obviously would be many other bugreports describing the issue for gnome-language-selector as it has a larger userbase. Of course, as a Kubuntu user, I don't use the gnome equivalent. :-) And as you can see, this patch is just against QtLanguageSelector.py...

Arne Goetje (arnegoetje)
Changed in language-selector:
assignee: nobody → jr
Revision history for this message
Colin Watson (cjwatson) wrote :

PyGTK doesn't tend to have the same kinds of problems with Unicode strings as PyQt does (as I've found from experience with Ubiquity).

Colin Watson (cjwatson)
Changed in language-selector:
status: Confirmed → Fix Committed
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package language-selector - 0.3.13

---------------
language-selector (0.3.13) intrepid; urgency=low

  [ Jonathan Riddell ]
  * QtLanguageSelector.py, fix unicode error

  [ David Gaarenstroom ]
  * Fix _ function in Qt frontend (LP: #279869).

  [ Colin Watson ]
  * Fix excessive capitalisation of "ubuntu" in e-mail addresses and URLs in
    debian/control.

  [ M. Vefa Bicakci ]
  * Fix handling of Unicode language names in Qt frontend (LP: #266971).

 -- Jonathan Riddell <email address hidden> Thu, 09 Oct 2008 10:47:37 +0100

Changed in language-selector:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.