localization - Load GTK-Glade translations in Windows using Python/PyGObject -
i have python script loads glade-gui can translated. works fine under linux, having lot of trouble understanding necessary steps on windows.
all 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 example ('de_de', 'utf-8')
, locale_dir
points @ folder has compiled mo-files.
under windows makes things more difficult:
locale.getlocale()
in python console returns (none, none)
, locale.getdefaultlocale()
returns ("de_de", "cp1252")
. furthermore when 1 tries set locale.setlocale(locale.lc_all, "de_de")
spit out 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 reader speculate why windows not accept common language codes. instead 1 forced use 1 of below lines:
locale.setlocale(locale.lc_all, "deu_deu")
locale.setlocale(locale.lc_all, "german_germany")
furthermore locale
module on windows not have bintextdomain
function. in order use 1 needs 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 questions, apart how works, is:
- which
intl.dll
need include? (i triedgnome/libintl-8.dll
source: http://sourceforge.net/projects/pygobjectwin32/, (pygi-aio-3.14.0_rev19-setup.exe)) - how can check if e.g. locale
deu_deu
gets correct/mo/de/lc_messages/appname.mo/
?
edit
my folder structure (is enough have de
folder? tried using deu_deu
folder 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 repository here: https://github.com/tobias47n9e/pygobject-locale
- and compiled windows installer (64 bit) here: https://www.dropbox.com/s/qdd5q57ntaymfr4/pygibank_1.0.exe?dl=0
short summary of answer
the mo
-files should go gnome-packages in way:
├── gnome │ └── share │ └── locale │ └── de | └── lc_messages | └── pygibank.mo
you close. complicated subject.
as wrote in question 10094335 , in question 3678174:
to setup locale user current locale not call:
locale.setlocale(locale.lc_all, locale.getlocale())
simply call:
locale.setlocale(locale.lc_all, '')
as explained in python setlocale
reference documentation.
this sets locale categories user’s default setting (typically specified in lang environment variable).
note windows doesn't have lang
environment variable set up, so, need before line:
import sys import os import locale if sys.platform.startswith('win'): if os.getenv('lang') none: lang, enc = locale.getdefaultlocale() os.environ['lang'] = lang
this make gettext work in-python translations.
how work can check in source code here:
https://github.com/python/cpython/blob/master/modules/_localemodule.c#l90
in particular, error you're getting:
locale.error: unsupported locale setting
is expressed here:
https://github.com/python/cpython/blob/master/modules/_localemodule.c#l112
which generic error message c call setlocale
failed given parameters.
the c call setlocale
defined in locale.h
header. in linux, is:
in windows, 1 used:
in windows locale.h
documentation can read:
the set of language , country/region strings supported setlocale listed in language strings , country/region strings.
and points to:
as can see, 2010 version setlocale
function expects locale in format found out: deu_deu
, differ 1 expected linux version de_de
. option use list of os-dependent locales setup locale. very sad indeed.
there issue here. if change version of toolchain can see newer version of setlocale
function work more closelly linux/posix does:
american english en-us
visual studio 2010 last release support old format, starting version 2012 new locale format expected.
as can imagine, 1 need use depends on version of toolchain cpython interpreter you're using built to. don't know version using according official python developer's guide:
python 3.5 , later use microsoft visual studio 2015. [...] python 3.3 , 3.4 use microsoft visual studio 2010. [...] python versions prior 3.3 use microsoft visual studio 2008. [...]
that related python locale
module. now, gettext
module or gettext related functions in locale
module, c library called libintl
.
libintl
called c library part of gettext translation magic:
one relevant part of documentation says:
note on gnu systems, don’t need link libintl because gettext library functions contained in gnu libc.
but in windows, because of issues explained in question 10094335 need load libintl
library being used pygobject, is, same linked during build. done doing steps wrote.
which intl.dll need include? (i tried gnome/libintl-8.dll source: http://sourceforge.net/projects/pygobjectwin32/, (pygi-aio-3.14.0_rev19-setup.exe))
so, yes. 1 used link against when pygobject aio build.
how can check if e.g. locale deu_deu gets correct /mo/de/lc_messages/appname.mo/
configure few messages , note if show translated. note, not folder "/mo/de/lc_messages/appname.mo/"
, appname.mo
file.
check first answer how create translation .po
file glade file.
Comments
Post a Comment