I have a Python script that loads a Glade-GUI that can be translated. Everything works fine under Linux, but I am having a lot of trouble understanding the necessary steps on Windows.
All that seems necessary under Linux is:
import locale
[...]
locale.setlocale(locale.LC_ALL, locale.getlocale())
locale.bindtextdomain(APP_NAME, LOCALE_DIR)
[...]
class SomeClass():
self.builder = Gtk.Builder()
self.builder.set_translation_domain(APP_NAME)
locale.getlocale() returns for example ('de_DE', 'UTF-8'), the LOCALE_DIR just points at the folder that has the compiled mo-files.
Under Windows this makes things more difficult:
locale.getlocale() in the Python console returns (None, None) and locale.getdefaultlocale() returns ("de_DE", "cp1252"). Furthermore when one tries to set locale.setlocale(locale.LC_ALL, "de_DE") will spit out this error:
locale.setlocale(locale.LC_ALL, "de_DE")
File "C:\Python34\lib\locale.py", line 592, in setlocale
return _setlocale(category, locale)
locale.Error: unsupported locale setting
I leave it to the reader to speculate why Windows does not accept the most common language codes. So instead one is forced to use one of the below lines:
locale.setlocale(locale.LC_ALL, "deu_deu")locale.setlocale(locale.LC_ALL, "german_germany")
Furthermore the locale module on Windows does not have the bintextdomain function. In order to use it one needs to import ctypes:
import ctypes
libintl = ctypes.cdll.LoadLibrary("intl.dll")
libintl.bindtextdomain(APP_NAME, LOCALE_DIR)
libintl.bind_textdomain_codeset(APP_NAME, "UTF-8")
So my questions, apart from how this works, is:
- Which
intl.dlldo I need to include? (I tried thegnome/libintl-8.dllfrom this source: http://sourceforge.net/projects/pygobjectwin32/, (pygi-aio-3.14.0_rev19-setup.exe)) - How can I check if the e.g. locale
deu_deugets the correct/mo/de/LC_MESSAGES/appname.mo/?
Edit
My folder structure (Is it enough to have a de folder? I tried using a deu_deu folder but that did not help):
├── gnome_preamble.py
├── installer.cfg
├── pygibank
│ ├── __init__.py
│ ├── __main__.py
│ ├── mo
│ │ └── de
│ │ └── LC_MESSAGES
│ │ └── pygibank.mo
│ ├── po
│ │ ├── de.po
│ │ └── pygibank.pot
│ ├── pygibank.py
│ └── ui.glade
└── README.md
- I put the repository here: https://github.com/tobias47n9e/pygobject-locale
- And the compiled Windows installer (64 bit) is here: https://www.dropbox.com/s/qdd5q57ntaymfr4/pygibank_1.0.exe?dl=0
Short summary of the answer
The mo-files should go into the gnome-packages in this way:
├── gnome
│ └── share
│ └── locale
│ └── de
| └── LC_MESSAGES
| └── pygibank.mo