i18n does not work due to wrong place of *.mo files (on Ubuntu)

Bug #284013 reported by Jean-Peer Lorenz
2
Affects Status Importance Assigned to Milestone
nssbackup
Fix Released
Medium
Oumar Aziz OUATTARA

Bug Description

i18n does not work due to wrong place of *.mo files (on Ubuntu):

* System: Ubuntu 8.04
* locale language: german (de_DE)
* nssbackup version: nssbackup-0.2-0~beta7

No items in UI were translated.

In nssbackup neither any UI text element gets translated to german nor any error messages occurs.

Installation of nssbackup using 'make install' places the i18n-files in '/usr/local/share/locale'.
Obviously this is not the correct place for storing localizations.

Moving the corresponding file 'nssbackup.mo' into the commonly used directory '/usr/share/locale' fixed the problem.
See the attached patch.

Tags: i18n ubuntu ui
Revision history for this message
Jean-Peer Lorenz (peer.loz) wrote :
Revision history for this message
Oumar Aziz OUATTARA (wattazoum) wrote :

Thank you Peer.

Unfortunately, I can't let NSsbackup install files in /usr/share/ when installing from 'make install' . This place is used by the deb installation (which is the standard) .
However there is clearly a problem as you mentioned it. I guess it's due to a mis-usage of gettext in NSsbackup. I'll look into it.

Changed in nssbackup:
assignee: nobody → wattazoum
importance: Undecided → Medium
milestone: none → release0.2
status: New → Confirmed
Revision history for this message
Jean-Peer Lorenz (peer.loz) wrote :

Another solution to this should be the explicit setting of the path to the locales.

The Python documentation suggests:

import gettext
gettext.bindtextdomain('myapplication', '/path/to/my/language/directory')
gettext.textdomain('myapplication')
_ = gettext.gettext
# ...
print _('This is a translatable string.')

However, this is not enough additional initialization if a programm uses Glade. The textdomain needs to be set up for Glade too.

See the modified file 'nssbackup-config-gui' that is attached. Of course, this is only an example. The literals need to be removed etc.

This works with 'pure' Python and Glade. Now the localization files were used from any given directory.

Greets.

Revision history for this message
Jean-Peer Lorenz (peer.loz) wrote :

For information:

There is still something wrong - translation of the UI (Glade) works so far, but none debug message were translated. I'll go into this.

Revision history for this message
Oumar Aziz OUATTARA (wattazoum) wrote :

Just FYI, I usually don't make the debug strings translatable.That might be the reason why you don't have the translations ...

Revision history for this message
Oumar Aziz OUATTARA (wattazoum) wrote :

I looked at your 'patch'. Looks good. I'll integrate it once I get home.

Revision history for this message
Jean-Peer Lorenz (peer.loz) wrote :

Hello,

I've looked into the whole i18n thing under Python and figured out the following:

If the translation files were stored in an arbitrary directory, it is possible to set up this directory before using the i18n functionality. Moreover, this is the recommend way by the Python documentation (...For this reason, it is always best to call bindtextdomain() with an explicit absolute path at the start of your application...)

To setup the gettext module there are actually two approaches:

1. following the GNU gettext API:

    import gettext
    from gettext import gettext as _ # declaration of _()
    application = 'nssbackup'
    locale_dir = '/usr/local/share/locale'
    gettext.bindtextdomain(application, locale_dir) # binds the domain to a directory
    gettext.textdomain(application) # and specifies the domain we want to use
    print _('_File')

2. this example uses the convenience function gettext.install():
There is function for convenience (gettext.install) in the Python module (AFAIK this function is not part of the GNU API) that does the same as 'bindtextdomain' and 'textdomain' and the declaration of _() within a single call.

    import gettext
    application = 'nssbackup'
    locale_dir = '/usr/local/share/locale'
    gettext.install(application, locale_dir)
    print _('_File')

For the setup of i18n support within Glade it is neccessary to call 'bindtextdomain' and 'textdomain', no function 'install' exists here.

So, the best practice for i18n support in nssbackup should be the use of the GNU gettext API because there is no 'install' function for Glade. This would look like:

    import gtk
    import gtk.glade
    import gettext
    from gettext import gettext as _ # declaration of _()
    application = 'nssbackup'
    locale_dir = '/usr/local/share/locale'
    gettext.bindtextdomain(application, locale_dir)
    gettext.textdomain(application)
    gtk.glade.bindtextdomain(application, locale_dir)
    gtk.glade.textdomain(application)
    ...

Of course this is neccessary for all related files, but i didn't modified all related files -> it didn't worked completly so far.

I added modified versions of all files that needs to be modified. Testing this was sucessful (UI and print statements now are translated). The Makefile needs no changes now.

Regards, Peer.

References:
http://www.python.org/doc/2.5.2/lib/node731.html
http://mail.python.org/pipermail/python-dev/2000-August/008537.html

Revision history for this message
Jean-Peer Lorenz (peer.loz) wrote :
Revision history for this message
Jean-Peer Lorenz (peer.loz) wrote :
Revision history for this message
Jean-Peer Lorenz (peer.loz) wrote :
Revision history for this message
Jean-Peer Lorenz (peer.loz) wrote :

Maybe it is useful to define the application's name and the path to the translation files within a module in the nssbackup package. Then these data could be imported by the touched files above.

Benefit: string literals were stored once in a single place.

Revision history for this message
Oumar Aziz OUATTARA (wattazoum) wrote :

I commited your fix to BZR : https://code.launchpad.net/~nssbackup-dev/nssbackup/0.2.
Thank a lot

Changed in nssbackup:
status: Confirmed → Fix Committed
Changed in nssbackup:
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.