Translating your Python/PyGTK application


In this tutorial we will go over the (very) basic steps that you can use in order to translate (localize or internationalize) your PyGTK application. For this tutorial we are going to use the PyWine application that we have been working with in two previous tutorials:

The full source and necessary files for this tutorial can be downloaded here.

Python translation

Creating our Portable Object Files

In order to translate our text we are going to use the gettext module. The gettext module is basically a wrapper for the GNU gettext utility whose documentation can be found here.

The first step is to edit our python file (pywine.py)and “mark” all of the strings that we want to translate in our python code. To do this we will use the _(“xxx”) standard that most people use to mark strings that need to be translated. Otherwise in situations like the following:

#Get the treeView from the widget Tree
self.wineView = self.wTree.get_widget("wineView")

“wineView” might be thought of as a string to be translated when it clearly should not be. So we need to go through the .py file and wrap each of my English strings in _(). Here are all of the strings that need to be marked in their marked form:

self.sWine = _("Wine")
self.sWinery = _("Winery")
self.sGrape = _("Grape")
self.sYear = _("Year")
self.show_error_dlg(_("Error opening file"))
self.show_error_dlg(_("Error opening file"))
file_dialog = gtk.FileChooserDialog(title=_("Select Project")
filter.set_name(_("pyWine database"))
filter.set_name(_("All files"))

The next step is to generate the Portable Object Template file using the command line gettext utility. If you are using Linux or OS X this should be no problem and gettext will probably already be installed. If you are using Windows the tools are available as .exe files from the GNU gettext FTP or this gettext for Win32 sourceforge project.

To create the PO Template you need to pass the gettext utility some information. The first thing is that the file being scanned is a python source file:

--language=Python

The second is that we only want to translate our marked strings:

--keyword=_

The third is that we want to create a .pot (PO template) file:

--output=pywine.pot

And the final argument is the file that we want to get the strings from:

pywine.py

So to put it all together it will look something like this:

xgettext --language=Python --keyword=_ --output=pywine.pot pywine.py

That would be all that we would have to use, but since we used Glade for our GUI we also have to extract and translate the strings from our Glade project. To do so the following line is used (taken from the great PyGTK FAQ entry: How do I internationalize a PyGTK and libglade program?):

intltool-extract --type=gettext/glade pywine.glade

That will create the file pywine.glade.h which contains the following:

char *s = N_("Add Wine");
char *s = N_("Edit Wine");
char *s = N_("Grape Variety: ");
char *s = N_("PyWine");
char *s = N_("Wine");
char *s = N_("Wine:");
char *s = N_("Winery: ");
char *s = N_("Year Produced: ");
char *s = N_("_About");
char *s = N_("_Add");
char *s = N_("_Edit");
char *s = N_("_File");
char *s = N_("_Help");
char *s = N_("_View");

You’ll notice that the strings are marked with the N_() mark. So when we create our PO template file we will want to take into account the pywine.py file, the pywine.glad.h file, the _() mark, and the N_() mark. To do so we will use the following command line:

xgettext --language=Python --keyword=_ --keyword=N_ --output=pywine.pot pywine.py pywine.glade.h

This will create a file named pywine.pot that contains the following:


# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR , YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2006-12-01 23:59-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME \n"
"Language-Team: LANGUAGE \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"

#: pywine.py:77 pywine.glade.h:5
msgid "Wine"
msgstr ""

#: pywine.py:78
msgid "Winery"
msgstr ""

#: pywine.py:79
msgid "Grape"
msgstr ""

#: pywine.py:80
msgid "Year"
msgstr ""

#: pywine.py:176 pywine.py:178
msgid "Error opening file"
msgstr ""

#: pywine.py:229
msgid "Select Project"
msgstr ""

#: pywine.py:237
msgid "pyWine database"
msgstr ""

#: pywine.py:242
msgid "All files"
msgstr ""

#: pywine.glade.h:1
msgid "Add Wine"
msgstr ""

#: pywine.glade.h:2
msgid "Edit Wine"
msgstr ""

#: pywine.glade.h:3
msgid "Grape Variety: "
msgstr ""

#: pywine.glade.h:4
msgid "PyWine"
msgstr ""

#: pywine.glade.h:6
msgid "Wine:"
msgstr ""

#: pywine.glade.h:7
msgid "Winery: "
msgstr ""

#: pywine.glade.h:8
msgid "Year Produced: "
msgstr ""

#: pywine.glade.h:9
msgid "_About"
msgstr ""

#: pywine.glade.h:10
msgid "_Add"
msgstr ""

#: pywine.glade.h:11
msgid "_Edit"
msgstr ""

#: pywine.glade.h:12
msgid "_File"
msgstr ""

#: pywine.glade.h:13
msgid "_Help"
msgstr ""

#: pywine.glade.h:14
msgid "_View"
msgstr ""

As you can see it contains both the translatable strings from the pywine.py file and the pywine.glade.h file. The next thing that we need to do is create a .PO (Portable Object) file. Each .PO file represents a specific translation to use. To create our PO file we will use the PO template file that we just created. We will use the msginit command line utility.

When running msginit we need to tell it what the input file is:

--input=pywine.pot

And what our current locale is. For me since I am an English speaking Canadian mine would be en_CA, which is language_COUNTRY. If I spoke Quebecois fluently (French Canadian) I might use fr_CA. You specify the locale as follows:

--locale=en_CA

If you want to see what locale you are, enter locale -a on the command line on a Unix-like operating system.

The command line to enter is as follows to create an English Canadian file:

msginit --input=pywine.pot --locale=en_CA

Let’s create an English US file as well

msginit --input=pywine.pot --locale=en_US

You may be asked for your email address so that someone can email you about your translation. If you entered the above you should see: en_CA.po and a en_US.po created in your pywine directory. Let’s edit this two files so that they are slightly different:

en_CA.po:

#: pywine.py:77 pywine.glade.h:5
msgid "Wine"
msgstr "Wine Canadian Style"

en_US.po:

#: pywine.py:77 pywine.glade.h:5
msgid "Wine"
msgstr "Wine US Style"

The next thing that we need to do is create the .mo file, which is the file that the gettext module will use for translation. The .mo files are simply binary versions of the ACSII .po files.

We first have to create the correct directory for the .mo files. Which is explained in bindtextdomain function for the Python gettext module:

bindtextdomain( domain[, localedir])
Bind the domain to the locale directory localedir. More concretely, gettext will look for binary .mo files for the given domain using the path (on Unix): localedir/language/LC_MESSAGES/domain.mo, where languages is searched for in the environment variables LANGUAGE, LC_ALL, LC_MESSAGES, and LANG respectively.

So for the above example we need to create the following directories:

en_CA/LC_MESSAGES
en_US/LC_MESSAGES

Which can be done using the following command:

mkdir -p en_CA/LC_MESSAGES
mkdir -p en_US/LC_MESSAGES

Now we use the msgfmt command line program to create our .mo files in the correct directory:

msgfmt --output-file=en_CA/LC_MESSAGES/pywine.mo en_CA.po
msgfmt --output-file=en_US/LC_MESSAGES/pywine.mo en_US.po

The Python Code

Now that we have our translation files ready we need to actually implement some python code in order to use them. Fortunately there really isn’t that much code for us to write, but I found a real lack of examples or information on the correct way to do this, and the code to be somewhat confusing.

The first step is to import the gettext and locale modules that we will use.

import locale
import gettext

The next step is to create a simple define for the domain of our translations, which is generally just the application name. The gettext module will use the domain name to look for .mo files. So if you domain is set to “12345″ gettext will look for 12345.mo files. You’ll notice that we created our .mo files are pywine.mo above so we are going to use “pywine” as our domain:

APP_NAME = "pywine"

Now, in general on a Unix like operating system you would install your .mo files into the correct locations in the /usr/lshare/locale directory. But since we are not installing this application and we want it to be easily portable to other operating systems, we will be storing the translations in the local directory.

Here is all of the code that we need to add to the __init__() function of the pywine class. It is quite complicated but hopefully the comments and my explanation after will make it easier to understand:

#Translation stuff

#Get the local directory since we are not installing anything
self.local_path = os.path.realpath(os.path.dirname(sys.argv[0]))
# Init the list of languages to support
langs = []
#Check the default locale
lc, encoding = locale.getdefaultlocale()
if (lc):
	#If we have a default, it's the first in the list
	langs = [lc]
# Now lets get all of the supported languages on the system
language = os.environ.get('LANGUAGE', None)
if (language):
	"""langage comes back something like en_CA:en_US:en_GB:en
	on linuxy systems, on Win32 it's nothing, so we need to
	split it up into a list"""
	langs += language.split(":")
"""Now add on to the back of the list the translations that we
know that we have, our defaults"""
langs += ["en_CA", "en_US"]

"""Now langs is a list of all of the languages that we are going
to try to use.  First we check the default, then what the system
told us, and finally the 'known' list"""

gettext.bindtextdomain(APP_NAME, self.local_path)
gettext.textdomain(APP_NAME)
# Get the language to use
self.lang = gettext.translation(APP_NAME, self.local_path
	, languages=langs, fallback = True)
"""Install the language, map _() (which we marked our
strings to translate with) to self.lang.gettext() which will
translate them."""
_ = self.lang.gettext

Now I will explain the code in smaller pieces so that it is easier to understand what is happening. The first step is to get the path to the python file that is running, it’s pretty straight forward so I won’t explain it her.

The first real step is get get a list of languages, or locales that we want to support. This list will be used to determine both the order in which we search for .mo files and what .mo files we look for.

The first locale we get is default locale, we use the locale module to get this:

# Init the list of languages to support
langs = []
#Check the default locale
lc, encoding = locale.getdefaultlocale()
if (lc):
	#If we have a default, it's the first in the list
	langs = [lc]

The next step is to get the list of languages supported from the operating system environment. The string that is returned by this needs to be parsed up into a list so we will also handle that. On Win32 and OS X this value is not set, so we need to make sure we check if it is None:

# Now lets get all of the supported languages on the system
language = os.environ.get('LANGUAGE', None)
if (language):
	"""langage comes back something like en_CA:en_US:en_GB:en
	on linuxy systems, on Win32 it's nothing, so we need to
	split it up into a list"""
	langs += language.split(":")

The final step in building our locale (or language) list is to add on the locales that we know we support, i.e. the .mo files that we have. We can add these to the list in whatever order we want, or if we are sure that they are all installed we could just add what we consider to be the default locale since we are sure that it will be found.

"""Now add on to the back of the list the translations that we
know that we have, our defaults"""
langs += ["en_CA", "en_US"]

Now the reason that we add these last, is so that we can let the user’s language settings control what .mo file is actually used to for the translations. We add our own just in case nothing is found.

The next step is to bind our domain (pywine) to a specific folder (the local folder) and then to set the current domain, this will be used when we perform the search for .mo files:

gettext.bindtextdomain(APP_NAME, self.local_path)
gettext.textdomain(APP_NAME)

Here are the explanations for both functions from the python documentation:

bindtextdomain( domain[, localedir])
Bind the domain to the locale directory localedir. More concretely, gettext will look for binary .mo files for the given domain using the path (on Unix): localedir/language/LC_MESSAGES/domain.mo, where languages is searched for in the environment variables LANGUAGE, LC_ALL, LC_MESSAGES, and LANG respectively.
If localedir is omitted or None, then the current binding for domain is returned.

textdomain( [domain])
Change or query the current global domain. If domain is None, then the current global domain is returned, otherwise the global domain is set to domain, which is returned.

The next step is to get the actual translation that we want to use and connect the getttext with the .mo file:

# Get the language to use
self.lang = gettext.translation(APP_NAME, self.local_path
	, languages=langs, fallback = True)

The gettext.translation() function is explained as follows:

translation( domain[, localedir[, languages[, class_[, fallback[, codeset]]]]])
Return a Translations instance based on the domain, localedir, and languages, which are first passed to find() to get a list of the associated .mo file paths. Instances with identical .mo file names are cached. The actual class instantiated is either class_ if provided, otherwise GNUTranslations. The class’s constructor must take a single file object argument. If provided, codeset will change the charset used to encode translated strings.
If multiple files are found, later files are used as fallbacks for earlier ones. To allow setting the fallback, copy.copy is used to clone each translation object from the cache; the actual instance data is still shared with the cache.
If no .mo file is found, this function raises IOError if fallback is false (which is the default), and returns a NullTranslations instance if fallback is true.

So the function will search for .mo files to each of the languages in langs in order and then returns a GNUTranslations object on success or a NullTranslations object on fail (since we set fallback to True.)

We then bind the object returned by translation’s gettext function to the _. So when you call _(“xxx”) you are really calling self.lang.gettext(“xxx”). Calling _(“XXX”) is just a convenient shorthand and somewhat of a standard way to “mark” strings for translation, as we saw above.

"""Install the language, map _() (which we marked our
strings to translate with) to self.lang.gettext() which will
translate them."""
_ = self.lang.gettext

So that’s really all you have to do. Now if you execute py wine using the following:

PyWine$ LANG=en_CA python pywine.py

Python translation

You will get the “Wine Canadian Style” header, then if you execute it as follows (on a Unix like OS):

PyWine$ LANG=en_CA python pywine.py

Python translation

You will get the “Wine US Style” header. Then if you execute it with French from France (on a Unix like OS):

PyWine$ LANG=fr_FR python pywine.py

The results depends on how your system is configured, and you will either get the Canadian text or the USA text.

The full source and necessary files for this tutorial can be downloaded here.

Conclusion

So that it for translation, using this method should work on all available operating systems with no problem. I wanted to include a language file for totally different language (i.e. a French, or Spanish, or whatever .mo file) but my skills in multiple spoken languages are not that strong.

So if anyone wants to perform a simple translation on the pywine.pot file and sent it to me that would be very much appreciated. Then we could start getting people to test this on systems with different language settings.

While researching this tutorial I came across some really good information from these sites:

As always if you come across any bugs or find any problems in the code please let me know!

selsine

del.icio.us del.icio.us

38 Responses to “Translating your Python/PyGTK application”

  1. JesĂşs
    Says:

    GREAT, you will be always the best.

    Please continue with yours articles :D

  2. pythy
    Says:

    locale module not required for gettext translation. If system environment set correctly then `import gettext` is enough.


    $ LANGUAGE=C ./gettext_test.py
    This is a test
    $ LANGUAGE=ru_RU ./gettext_test.py
    Это просто тест
    $ cat ./gettext_test.py

    #!/usr/bin/env python
    
    import gettext
    
    gettext.install('test', './locales', unicode=True)
    print _(u"This is a test")

    And it is not required to use GNU gettext binaries, because pygettext and msgfmt.py comes with Python.

  3. selsine

    selsine
    Says:

    Jesus – Thanks for the kind words.

    Pythy – Thanks for the information. I tried simply using gettext on my debian machine however it never seem to grab the correct language. Once I switched to using my method everything seemed to work. I will look at it a bit more.

    Also thanks for mentioning pygettext and msgfmt.py, I was going to use those but then I read in some places that there were some problems with those and Glade, so I just when the GNU route. I will look into that as well.

    It looks like you’ve got some really neat things happening on your website as well, too bad I dont’ speak any Russian!

  4. Jason Roberts
    Says:

    Regarding Pythy’s comments.

    If the program will be used on Windows, I believe it is a good idea to not just rely on gettext’s behavior of searching only the environment strings for the list of languages. (From what I can tell from reading the Python 2.4.4 implementation, gettext.find only searches the env strings; it does not call the locale module to obtain either the current or default locale.) These env vars are typically not set on Windows.

    If you are developing library modules rather than a stand-alone Python program, it seems like a good idea to first try the language returned by locale.getlocale before trying locale.getdefaultlocale, in case the program that imported your module has changed the locale.

  5. selsine

    selsine
    Says:

    Hi Jason,

    Thanks for the information, that’s part of the problem that I had with this translation work. There is a lot of information out there but it’s really difficult to figure out exactly what all of it means.

    Also, good tip for translation modules.

  6. Nação Livre » Blog Archive » VocÄ‚Åž jÄ‚Ä„ Garimpou hoje?
    Says:

    [...] http://www.learningpython.com/2006/12/03/translating-your-pythonpygtk-application/ [...]

  7. fossilet
    Says:

    Hi, selsine

    I changed the menu name _File to _Fichier in en_CA.po, like below:
    #: pywine.glade.h:12
    msgid “_File”
    msgstr “_Fichier”

    and then run

    msgfmt –output-file=en_CA/LC_MESSAGES/pywine.mo en_CA.po

    and

    LANG=en_CA python pywine.py

    but the menu name won’t change in the GUI. How can I translate them? Thanks.

  8. selsine

    selsine
    Says:

    Hi fossilet,

    There is actually an error in the tutorial. What you need to do is add the following two lines to the program in the position indicated:

    gettext.bindtextdomain(APP_NAME, self.local_path)
    gettext.textdomain(APP_NAME)
    #Add these two lines here to get Glade stuff to translate
    gtk.glade.bindtextdomain(APP_NAME, self.local_path)
    gtk.glade.textdomain(APP_NAME)

    Thanks for bringing this to my attention and sorry if it caused you any pain.

  9. Lord Taran
    Says:

    Have you tried to open de Open File or Save File dialog? I have an error:
    Traceback (most recent call last):

    File “pywine3.py”, line 192, in on_file_open
    open_file = self.file_browse(gtk.FILE_CHOOSER_ACTION_OPEN)
    File “pywine3.py”, line 265, in file_browse
    file_dialog = gtk.FileChooserDialog(title=_(“Select Project”)

    I’ve read the PyGTK FAQ Entry and I’ve made some changes: I’ve add the following line:

    _ = gettext.gettext
    FILE_EXT = "pwi"
    APP_NAME = "pywine"

    But if I do that almost all the translation stuff code is not used, because we will not call gettext.translations, so we don’t use langs or language. So if I comment all the translation stuff lines except:

    self.local_path = os.path.realpath(os.path.dirname(sys.argv[0]))
    gettext.bindtextdomain(APP_NAME, self.local_path)
    gettext.textdomain(APP_NAME)
    gtk.glade.bindtextdomain(APP_NAME, self.local_path)
    gtk.glade.textdomain(APP_NAME)

    It works perfectly. But after the Jason’s comment I don’t know if it will work in Windows…

  10. Lord Taran
    Says:

    PD: How can I color the python code in my comment?

  11. selsine

    selsine
    Says:

    Hi Lord Taran,

    Good catch! Thanks for the information and sorry that it took me so long to reply I was away from the computer all weekend.

    I looked into this a little bit and this is what I did to solve the problem:

    _ = gettext.gettext
    FILE_EXT = "pwi"
    APP_NAME = "pywine"
    """Install the language, map _() (which we marked our
    strings to translate with) to self.lang.gettext() which will
    translate them."""
    global _
    _ = self.lang.gettext

    That way when PyWine is initialized it will change the value of the global _ to be the correct translated function. I’ve tested it and it seems to work let me know what you think.

    To highlight your code use the following:

    [_code_ lang="python"]
    [/_code_]

    Simply remove the _ around code.

  12. Las Noyas de Taran
    Says:

    [...] Este es el cuarto tutorial que intento acercar a los hispanohablantes de los escritos por Mark Mruss en su magnĂ­fica web Learning Python. Esta vez me ha tomado mĂĄs tiempo ya que el cĂłdigo, tal y como se generaba siguiendo los pasos del tutorial, no funcionaba correctamente. Pero gracias a los comentarios, un pelĂ­n de investigaciĂłn y los conocimientos de Mark ya estĂĄ listo para publicarse. Cada vez tengo mĂĄs claro que Mark es un crack, lĂĄstima que no entienda castellano y no vaya a leer esto xD Antes de pasar al tutorial en sĂ­ pediros un poquito de feedback. Seguro que hay cosas que he traducido regular, por no decir como el culo, y a lo mejor se me ha pasado algo en el cĂłdigo fuente al copiar y pegar o lo que sea, asĂ­ que os agradecerĂ­a todo comentario que sirviera para mejorar estas traducciones. Esta vez vamos a preparar nuestra aplicaciĂłn para que pueda traducirse con facilidad a otros idiomas, verĂŠis lo que mola gettext para estas cosas, y lo fĂĄcil que es localizar una aplicaciĂłn asĂ­. El artĂ­culo original se llama Translating your Python/PyGTK application: En este tutorial veremos los pasos (muy) bĂĄsicos para traducir (localizar o internacionalizar) tu aplicaciĂłn PyGTK. Para este tutorial vamos a utilizar la aplicaciĂłn PyWine en la que hemos estado trabajando en los dos tutoriales anteriores: [...]

  13. Lord Taran
    Says:

    The language file that I’ve used to do the spanish translation:
    ::HLIGHT_BLOCK_1::

  14. Packo
    Says:

    Thanks for the tutorial-

  15. selsine

    selsine
    Says:

    You are welcome Packo!

  16. myspacetotal
    Says:

    myspacetotal

    Interesting Article.

  17. Lars Friedrichs
    Says:

    Hi,

    thanks for this nice tut. I shamelessly cut’n'pasted the needed python code into my project BlueProximity at http://blueproximity.sourceforge.net which I hope is OK to you. You will get credits in the Changelog as being helpful with the translation infrastructure if that is alright with you. Please mail me for details.

    Bye
    Lars

  18. selsine

    selsine
    Says:

    Hi Lars,

    Feel free to use the code, in fact I’m glad that people are using it in there programs, makes me feel useful!

    If you want to do anything for me you could mention my name: Mark Mruss and my blog: http://www.learningpython.com

    That would be very cool!

    Good luck!

  19. Nano
    Says:

    hi, cool article, but how to translate tooltips?

    I have the following:

    tooltips = gtk.Tooltips()

    self.button1 = self.wTree.get_widget(“button1″)
    tooltips.set_tip(_(self.button1, “Configure the Bash”))

    but then i start the app i get:

    Traceback (most recent call last):
    File “/usr/bin/nix-style.real”, line 109, in ?
    hwg = NixStyleTen()
    File “/usr/bin/nix-style.real”, line 67, in __init__
    tooltips.set_tip(_(button1, “Configure the Bash”))
    TypeError: gettext() takes exactly 2 arguments (3 given)

    i got no clue

  20. selsine

    selsine
    Says:

    Hi Nano,

    You are using the gettext() function incorrectly, you need to only pass it text instead of text and the button.

    Try this:

    self.button1 = self.wTree.get_widget(”button1″)
    tooltips.set_tip(self.button1, _(“Configure the Bash”))

    Also remember that if you are configuring the tips in Glade the translation should already be taken care of.

  21. Nano
    Says:

    Ahh, of course … thanks a lot.

  22. JulioBiason.Net
    Says:

    [...] Information extracted from this page. [...]

  23. Kopfgeldjaeger
    Says:

    Hello! Your code (example code in gunzip archive) does not really work for me as it should. But that’s not that bad, because I know have a very short solution for Python+PyGTK+Gettext+Glade:

    [codelang="python"]#

    APP = “gvdown”
    DIR = “po”

    gtk.glade.bindtextdomain(APP, DIR)
    gtk.glade.textdomain(APP)

    #
    greetings

  24. Eiwot
    Says:

    Great !!!

  25. Charles Merriam
    Says:

    First, thank you for the excellent write-up. Very few examples of using internationalization and localization exist for Python.

    Second, many operating systems, including Ubuntu, fail to explicitly set the LANGUAGE variable. This leads to many non-working pieces of code. Your solution is one of the few that addresses this correctly.

    Third, the most simple usage of “from gettext import gettext.gettext as _” is often used as a temporary solution between coding your Python program and localizing it. Alternately, some put in the placeholder “def _(str): str” to allow coding in internationalization before beginning it.

    Finally, could you explain the odd issues of making a translation for a language. That is, will a locale of “de_DE” grab the “de” translation if there is no “de_DE” directory?

    Great article!

  26. fossilet
    Says:

    @Charles,

    Yes, I must use LANGUAGE=zh_CN prefix instead of LANG=zh_CN to fully localize my PyGTK program on Ubuntu system, even if I use the code selsine provides.

  27. ganesh gajare
    Says:

    hi selsine,
    Thanks for the tutor. I have configured each and everythins as per that. But i got error: Gtk-WARNING **: Locale not supported by C library.
    Using the fallback ‘C’ locale.

    Bcos of which i can’t work forward. My project is stop in-between will you please help me for this.

  28. Nisha Pandita
    Says:

    I have a problem of locale,i have set my os(ubantu) locale to en_us,its like that your example pywine.py i am able to translate only in the locale i have set my operating system to,i want translations to happen in say en_CA, i have done all the required things like creating pot files,po file ,editing po ffiles,creating folders,creating mo files but then also i am getting an error.
    \\Gtk-WARNING **: Locale not supported by C library.
    Using the fallback ‘C’ locale.\\

    please help me out….will be quite greattful to you

  29. Nisha Pandita
    Says:

    hi selsine

    i working on an application that is build in python, pygtk and glade but i say i add any module to the application ,i need to again generate all the pot files and po files,again after creating the po files all translations vanish up and we are left with to again add the translations for the whole application,is there anything can be done regarding it or at least that if we again generate the po files, the already translated files are not affected….

    Please help me out and thanks for your tutorial

  30. Damon Lynch
    Says:

    Thank you very much for writing this tutorial. I have also included my thanks in the ChangeLog for my project, Rapid Photo Downloader.

    One comment: while testing out translations people had done for my project, I spent some hours trying to figure out why the strings generated by Python code would be translated without difficulty, while the glade generated GUI would not be translated at all. On Ubuntu, the solution is to replace this (for example):

    LANG=fr_FR ./code-to-run

    with this:

    LANG=fr_FR.UTF-8 ./code-to-run

    The second method works just fine.

    Another comment: I was able to translate combobox values by subclassing gtk.ComboBox, storing the “real” value in a hidden 1st column, and displaying the translated value in a 2nd column, which is what the user sees. Perhaps there is a better way but this works fine for me at the moment.

  31. Bob
    Says:

    I liked your example, it helped me understand quickly how to use gettext.

    You might want to fix your link to the updated source – you have it all lowercase as pywine_03.tar.gz and it gets a 404.

    I downloaded the source successfully after seeing that the original article called it PyWine.tar.gz, so I tried PyWine_03.tar.gz

    Thanks, again,
    Bob

  32. Malac
    Says:

    Couldn’t see this anywhere so thought I’d post it.
    Your code would not work for glade file widgets until I changed this:
    [code lang=python] self.wTree = gtk.glade.XML(self.gladefile,"config")[/code]
    to this:
    [code lang=python] self.wTree = gtk.glade.XML(self.gladefile,"config", gtk.glade.textdomain(APP_NAME))[/code]

  33. Muhamed Niyas
    Says:

    Its very nice tutorial…
    Labels in the Glade Translating well in Ubuntu and Debian.
    But its not working in Windows. Can you pls guide me to
    solve this issue?

    Thanks in advance

  34. fracpete
    Says:

    Very cool website. Thanks for that!

    The link to the source code (in the paragraph above the \Conclusion\) links to \pywine_03.tar.gz\ (giving you a 404), but it should read \PyWine_03.tar.gz\ instead.

  35. xishan
    Says:

    Very good tutorial. Thanks alot.

    It was working fine on jaunty before I upgraded to karmic koala.
    Any suggestions?

  36. Jonas
    Says:

    ganesh, Nisha Pandita
    Just replace LANG with LANGUAGE when executing the program.

  37. onlinebusiness,internet business,maketing,oppurtunity
    Says:

    onlinebusiness,internet business,maketing,oppurtunity…

    [...]learning python » Blog Archive » Translating your Python/PyGTK application[...]…

  38. xcfaudio
    Says:

    # In addition to your code:
    if (lc):
    langs = [lc]
    # complementary code : append xx from xx_XX
    if len(lc) == 5:
    str_lang = lc[0:2]
    if str_lang not in langs:
    langs.append( str_lang )

Leave a Reply

 

Popular Posts