简体   繁体   中英

Internationalizing python apps

I have seen a lot of tutorials to internationalize python apps. I have tried this solution and works fine: Translating your Python/PyGTK application . I mean, it works fine with helloworld .

I have followed the same steps for my "big" program and it does not work. This is the python code that I pasted on my code:

import os, locale, gettext
APP_NAME = "myapp"

# 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", "es_ES"]

"""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

When I execute:

$ LANG=es_ES python myapp.py

I get:

$ Gtk-WARNING **: Locale not supported by C library.
Using the fallback 'C' locale.

If I execute the same LANG configuration for helloworld it works fine.

Any idea how to fixx the problem?

On my system, this is what is working:

$ LANGUAGE=es_ES python myapp.py

Hope it works!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM