2014-10-05 117 views
1

我看過很多教程來國際化python應用程序。我已經試過這個解決方案,並且工作正常:Translating your Python/PyGTK application。我的意思是,它可以很好地與helloworld國際化python應用程序

我對我的「大」程序採取了相同的步驟,但它不起作用。這是我在我的代碼粘貼Python代碼:

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 

當我執行:

$ LANG=es_ES python myapp.py 

我得到:

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

如果我執行相同的LANG配置helloworld它工作正常。

任何想法如何解決這個問題?

回答

0

在我的系統,這是什麼工作:

$ LANGUAGE=es_ES python myapp.py 

希望工程!