wxPython i18n没有加载

时间:2016-01-24 14:10:21

标签: python internationalization wxpython locale

我在使用wxPython加载i18n时遇到了麻烦。这是我的文件结构:

locale
│  lembox.pot
│
├─de_DE
│  └─LC_MESSAGES
│          lembox.mo
│          lembox.po
│
├─en_GB
│  └─LC_MESSAGES
│          lembox.mo
│          lembox.po
│
└─en_US
    └─LC_MESSAGES
            lembox.mo
            lembox.pot

lembox.pot看起来像这样:

# LemBox
# Copyright (C) 2016
# Drew Lemmmy <drew@lemmmy.pw>, 2016.
#
msgid ""
msgstr ""

"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2016-01-23 23:27+GMT Standard Time\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: ENCODING\n"
"Generated-By: pygettext.py 1.5\n"

示例.po文件如下所示:

# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: LemBox\n"
"POT-Creation-Date: 2016-01-23 23:44+0000\n"
"PO-Revision-Date: 2016-01-23 23:45+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: de_DE\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: pygettext.py 1.5\n"
"X-Generator: Poedit 1.8.6\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Poedit-Basepath: ..\n"
"X-Poedit-SearchPath-0: lembox.py\n"
"X-Poedit-SearchPath-1: main_app.py\n"
"X-Poedit-SearchPath-2: utility.py\n"
"X-Poedit-SearchPath-3: hash_util.py\n"

#: hash_util.py:13
msgid "hash_shortcut"
msgstr "Hash bilden"

#: hash_util.py:16
msgid "hash_title"
msgstr "Hashbildung"

#: main_app.py:37
msgid "exit"
msgstr "Beenden"

#: main_app.py:45
msgid "LemBox"
msgstr "LemBox"

#: utility.py:21
#, python-format
msgid "LemBox - %s"
msgstr "LemBox - %s"

#, fuzzy
#~ msgid "Hash"
#~ msgstr "Hash"

在我的代码中,我加载了这样的语言环境:

def main():
    app = wx.App(False)
    locale = wx.Locale()
    locale.AddCatalogLookupPathPrefix('.')
    locale.AddCatalog('de_DE')
    app.MainLoop()

当然,请使用以下文字:_("hash_shortcut")(当前已定义_ = wx.GetTranslation。)

但是,在我的应用程序中,我看到的只是未翻译的字符串。这里的问题是什么?

编辑:我在应用程序中按字面意思&#34; hash_shortcut&#34;,&#34; hash_title&#34;等等。

1 个答案:

答案 0 :(得分:2)

尝试以下方法:

locale = wx.Locale()
locale.AddCatalogLookupPathPrefix('./locale')
locale.Init(wx.LANGUAGE_GERMAN)
locale.AddCatalog('lembox')

Init加载来自wxpython的默认德语位,例如日历中的日期,而AddCatalog通常是messages,其中mo文件是messsages.mo但是你有叫它lembox.mo

或者,你离开

locale.AddCatalogLookupPathPrefix('.')

按原样,将lembox.mo的副本放在本地目录中,仍然使用

locale.AddCatalog('lembox')