Drew Lemmy
Drew Lemmy

Reputation: 447

wxPython i18n not loading

I'm having trouble getting my i18n to load in wxPython. Here is my file structure:

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 looks like this:

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 <[email protected]>\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"

A sample .po file looks like this:

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

In my code, I load the locale like so:

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

And of course, use the text like this: _("hash_shortcut") (with _ = wx.GetTranslation previously defined, of course.)

However, in my application, all I see is the untranslated strings. What's the problem here?

Edit: I see literally "hash_shortcut", "hash_title", etc in my application.

Upvotes: 1

Views: 257

Answers (1)

Rolf of Saxony
Rolf of Saxony

Reputation: 22438

Try the following:

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

The Init loads the default german bits from wxpython for things like dates in calendars for example and the AddCatalog would normally be messages where the mo file is messsages.mo but you have called it lembox.mo

Alternatively, you leave

locale.AddCatalogLookupPathPrefix('.')

as is, and put a copy of lembox.mo in the local directory and still use

locale.AddCatalog('lembox')

Upvotes: 2

Related Questions