After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 328652 - Autotranslation of gedit-test-utf8-procedural-api.py fails with gedit-2.13
Autotranslation of gedit-test-utf8-procedural-api.py fails with gedit-2.13
Status: RESOLVED FIXED
Product: dogtail
Classification: Deprecated
Component: Framework
CVS HEAD
Other Linux
: Normal normal
: ---
Assigned To: Zack Cerza
Dogtail Maintainers
Depends on:
Blocks:
 
 
Reported: 2006-01-25 22:49 UTC by Dave Malcolm
Modified: 2006-02-01 17:36 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
final nail in the coffin (4.18 KB, patch)
2006-02-01 01:43 UTC, Zack Cerza
committed Details | Review

Description Dave Malcolm 2006-01-25 22:49:22 UTC
Running CVS pyspi and dogtail as of 24th January 2006
 with gedit-2.13.1-2 on Fedora (rawhide, development to FC5).

[dmalcolm@cassandra examples]$ LANG=ja_JP.UTF-8 ./gedit-test-utf8-procedural-api .py
Creating logfile at /tmp/dogtail/logs/gedit-test-utf8-procedural-api_20060125-17 3747 ...
Detecting distribution: Red Hat/Fedora/derived distribution
Bonobo accessibility support initialized
GTK Accessibility Module initialized
/tmp/dogtail/screenshot_20060125-173801.png
Screenshot taken: /tmp/dogtail/screenshot_20060125-173801.png
click on {child with name="Save" ("保存(S)", "保存")}
Translation not found for "Save As…"
searching for child of Node roleName='application' name='gedit' description='': "Save As…" dialog (attempt 3)
searching for child of Node roleName='application' name='gedit' description='': "Save As…" dialog (attempt 4)
searching for child of Node roleName='application' name='gedit' description='': "Save As…" dialog (attempt 5)
searching for child of Node roleName='application' name='gedit' description='': "Save As…" dialog (attempt 6)
searching for child of Node roleName='application' name='gedit' description='': "Save As…" dialog (attempt 7)
searching for child of Node roleName='application' name='gedit' description='': "Save As…" dialog (attempt 8)
searching for child of Node roleName='application' name='gedit' description='': "Save As…" dialog (attempt 9)
searching for child of Node roleName='application' name='gedit' description='': "Save As…" dialog (attempt 10)
searching for child of Node roleName='application' name='gedit' description='': "Save As…" dialog (attempt 11)
searching for child of Node roleName='application' name='gedit' description='': "Save As…" dialog (attempt 12)
searching for child of Node roleName='application' name='gedit' description='': "Save As…" dialog (attempt 13)
searching for child of Node roleName='application' name='gedit' description='': "Save As…" dialog (attempt 14)
searching for child of Node roleName='application' name='gedit' description='': "Save As…" dialog (attempt 15)
searching for child of Node roleName='application' name='gedit' description='': "Save As…" dialog (attempt 16)
searching for child of Node roleName='application' name='gedit' description='': "Save As…" dialog (attempt 17)
searching for child of Node roleName='application' name='gedit' description='': "Save As…" dialog (attempt 18)
searching for child of Node roleName='application' name='gedit' description='': "Save As…" dialog (attempt 19)
Translation not found for "Save as..."
searching for child of Node roleName='application' name='gedit' description='': "Save as..." dialog (attempt 3)
searching for child of Node roleName='application' name='gedit' description='': "Save as..." dialog (attempt 4)
searching for child of Node roleName='application' name='gedit' description='': "Save as..." dialog (attempt 5)
searching for child of Node roleName='application' name='gedit' description='': "Save as..." dialog (attempt 6)
searching for child of Node roleName='application' name='gedit' description='': "Save as..." dialog (attempt 7)
searching for child of Node roleName='application' name='gedit' description='': "Save as..." dialog (attempt 8)
searching for child of Node roleName='application' name='gedit' description='': "Save as..." dialog (attempt 9)
searching for child of Node roleName='application' name='gedit' description='': "Save as..." dialog (attempt 10)
searching for child of Node roleName='application' name='gedit' description='': "Save as..." dialog (attempt 11)
searching for child of Node roleName='application' name='gedit' description='': "Save as..." dialog (attempt 12)
searching for child of Node roleName='application' name='gedit' description='': "Save as..." dialog (attempt 13)
searching for child of Node roleName='application' name='gedit' description='': "Save as..." dialog (attempt 14)
searching for child of Node roleName='application' name='gedit' description='': "Save as..." dialog (attempt 15)
searching for child of Node roleName='application' name='gedit' description='': "Save as..." dialog (attempt 16)
searching for child of Node roleName='application' name='gedit' description='': "Save as..." dialog (attempt 17)
searching for child of Node roleName='application' name='gedit' description='': "Save as..." dialog (attempt 18)
searching for child of Node roleName='application' name='gedit' description='': "Save as..." dialog (attempt 19)
Traceback (most recent call last):
  • File "./gedit-test-utf8-procedural-api.py", line 61 in ?
    focus.dialog('Save as...')
  • File "/home/boston/dmalcolm/coding/dogtail/pristine-from-cvs/dogtail/dogtail/p rocedural.py", line 82 in __call__
    else: raise FocusError, name
dogtail.procedural.FocusError: Save as...


Problem seems to be in: gedit/gedit-commands-file.c: file_save_as specifies the trasnslatable string in the source file as _("Save As\342\200\246").

"Save As\342\200\246" is an octal encoding of a NUL-terminated UTF-8 encoded string consisting of "Save As" followed by the U+2026 HORIZONTAL ELLIPSIS unicode character.

Looking in the packaged mo file I see the same encoded string.
hexdump -C /usr/share/locale/ja/LC_MESSAGES/gedit.mo | grep -C 3 "Save As"
00008e10  20 31 31 00 53 61 6e 73  20 38 00 53 61 6e 73 20  | 11.Sans 8.Sans |
00008e20  52 65 67 75 6c 61 72 20  31 31 00 53 61 6e 73 20  |Regular 11.Sans |
00008e30  52 65 67 75 6c 61 72 20  38 00 53 61 72 64 69 6e  |Regular 8.Sardin|
00008e40  69 61 6e 00 53 61 76 65  00 53 61 76 65 20 41 73  |ian.Save.Save As|
00008e50  e2 80 a6 00 53 61 76 65  20 5f 41 73 2e 2e 2e 00  |....Save _As....|
00008e60  53 61 76 65 20 61 6c 6c  20 6f 70 65 6e 20 66 69  |Save all open fi|
00008e70  6c 65 73 00 53 61 76 65  20 74 68 65 20 63 68 61  |les.Save the cha|

Looks like it's failing to locate the translation in the call to gettext.dgettext().  What is the encoding to strings passed to GNU gettext, or what rules cover this?  The test currently searches for that unicode string directly.
Comment 1 Zack Cerza 2006-01-25 23:18:35 UTC
oddly enough, es_ES.UTF-8 and fr_FR.UTF-8 still work for me.
Comment 2 Lawrence Lim 2006-01-26 23:07:05 UTC
I saw that issue before while working on Bug 320561. Managed to get around it using ugettext instead of dgettext. IMHO, I think ugettext would handle unicode better. Found another example regarding python with gettext as well.

<http://mail.python.org/pipermail/python-dev/2003-April/034511.html>


Hope it helps.
Comment 3 Zack Cerza 2006-01-27 00:47:29 UTC
At first I couldn't find this 'uggettext' thing you were talking about. I eventually found it. The way we're currently doing things is:

<figure out what translation domains we need>
gettext.dgettext(domain, stringToTranslate)

The way we'd need to use ugettext, unless I'm wrong:

<figure out what mo-files we need>
trans=gettext.GNUTranslations(open(fileName))
trans.ugettext(stringToTranslate)

Which will require a slight refactoring of dogtail.i18n. Or am I missing something?
Comment 4 Lawrence Lim 2006-01-27 01:01:43 UTC
Yes, I think it would involve some changes for dogtail to handle unicode. Please try if it helps.

<http://bugzilla.gnome.org/attachment.cgi?id=54256&action=view>

+		# ensure that there is actually mo exist file that locale
+		if (os.path.isfile(fullPath)):
+			gettext.bindtextdomain (self.domainName, "/usr/share/locale/")
+			gettext.textdomain (self.domainName)
+			t = gettext.translation(self.domainName, "/usr/share/locale/")
+			_ = t.ugettext
+			result = _(srcName)
Comment 5 Zack Cerza 2006-01-27 01:58:20 UTC
OK, it looks like I've got a fix hacked up using ugettext(), with a net loss of 20 lines - yay! I happened to fix two other bugs, also - yay!

I forgot to attach the patch before I committed, so here's the link to the commit:
http://cvs.gnome.org/bonsai/cvsquery.cgi?branch=&dir=dogtail&who=zcerza&date=explicit&mindate=2006-01-26%2020:54&maxdate=2006-01-26%2020:56
Comment 6 Dave Malcolm 2006-01-27 02:37:55 UTC
Unfortunatly there looks to be a regression here :-(

I just tested CVS HEAD on my Fedora rawhide box.  A judicious "print moFile" statement in GettextTranslationDb __init__ shows that it's loading the moFile for every single language, not just the one under test (and it does it for every package in the dependenct chain, so it's a lot of mo files...)  

LANG=ja_JP.UTF-8 ./gedit-test-utf8-procedural-api.py
Creating logfile at /tmp/dogtail/logs/gedit-test-utf8-procedural-api_20060126-212739 ...
Detecting distribution: Red Hat/Fedora/derived distribution
/usr/share/locale/af/LC_MESSAGES/gedit.mo
/usr/share/locale/am/LC_MESSAGES/gedit.mo
[   lots of mo files snipped   ]
/usr/share/locale/mn/LC_MESSAGES/GConf2.mo
/usr/share/locale/ms/LC_MESSAGES/GConf2.mo
/usr/share/locale/nb/LC_MESSAGES/GConf2.mo
/usr/share/locale/ne/LC_MESSAGES/GConf2.mo
Traceback (most recent call last):
  • File "./gedit-test-utf8-procedural-api.py", line 18 in ?
    dogtail.i18n.loadTranslationsFromPackageMoFiles('gedit')
  • File "/home/boston/dmalcolm/coding/dogtail/pristine-from-cvs/dogtail/dogtail/i18n.py", line 199 in loadTranslationsFromPackageMoFiles
    load(packageName, getDependencies)
  • File "/home/boston/dmalcolm/coding/dogtail/pristine-from-cvs/dogtail/dogtail/i18n.py", line 180 in load
    translationDbs.append(GettextTranslationDb(moFile))
  • File "/home/boston/dmalcolm/coding/dogtail/pristine-from-cvs/dogtail/dogtail/i18n.py", line 49 in __init__
    self.__gnutranslations = gettext.GNUTranslations(open(moFile))
  • File "/usr/lib/python2.4/gettext.py", line 177 in __init__
    self._parse(fp)
  • File "/usr/lib/python2.4/gettext.py", line 301 in _parse
    plural = v[1].split('plural=')[1]
IndexError: list index out of range

This fatal error is isolatable to a simple reproducer:
Python 2.4.2 (#1, Dec 17 2005, 13:02:22)
[GCC 4.1.0 20051214 (Red Hat 4.1.0-0.9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gettext
>>> gettext.GNUTranslations(open("/usr/share/locale/ne/LC_MESSAGES/GConf2.mo"))
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.4/gettext.py", line 177, in __init__
    self._parse(fp)
  File "/usr/lib/python2.4/gettext.py", line 301, in _parse
    plural = v[1].split('plural=')[1]
IndexError: list index out of range

Do you want me to file separate bugs for:
(i) the multilanguage loading thing?
(ii) the mo file that can't be loaded?

It may be that various translation files are broken (e.g. the specific one above), and that's causing the problem, but if so the loading of excessive numbers of language files is more likely to trigger that bug.

Grrrr :-(
Comment 7 Zack Cerza 2006-01-27 18:56:21 UTC
Grrr indeed. Well, I just committed a fix that filters the list of mo-files so that we only get the language we want. Unfortunately there's still more to do, it seems...
Comment 8 Zack Cerza 2006-02-01 01:43:14 UTC
Created attachment 58491 [details] [review]
final nail in the coffin

This patch should be the final nail in the coffin of this bug. Lots of encoding-related fixed.
Comment 9 Zack Cerza 2006-02-01 02:16:02 UTC
Er, "fixes".

Anyway, I just committed the patch. I'm closing the bug because all my testing went fine, but feel free to reopen it if you find more problems.
Comment 10 Lawrence Lim 2006-02-01 02:51:11 UTC
I did find some problem with the patch.

# LANG=ja_JP.UTF-8 ./gedit-test-utf8-procedural-api.py
Creating logfile at /tmp/dogtail/logs/gedit-test-utf8-procedural-api_20060201-024349 ...
Detecting distribution: Red Hat/Fedora/derived distribution
Segmentation fault
Comment 11 Zack Cerza 2006-02-01 17:36:23 UTC
(In reply to comment #10)
Well, no python code should ever cause the python interpreter to crash. This has to be either python's, pyspi's, or some other C-written module's fault. Maybe the rpm bindings?