[wxPython-users] Use another or native Language
Werner F. Bruhin
werner.bruhin at free.fr
Mon Aug 14 02:06:11 PDT 2006
Hi Franz,
Have you seen the wiki pages?
http://wiki.wxpython.org/index.cgi/Internationalization
http://wiki.wxpython.org/index.cgi/RecipesI18n?highlight=3D%28i18n%29
Franz Steinh=E4usler wrote:
>Hi Robin,
>
>I wondered, in the Demo it worked and not in Pycrust or another applicatio=
n.
>
>So I discovered, in the already wrapped dialogs, this work,
>but if you use _("string") in Python you get:
> =
> Traceback (most recent call last):
> File "<input>", line 1, in ?
> NameError: name '_' is not defined
> =
>
>Therefore if you try to get the translation (the wxPython wxstd.mo), =
> you have apparantly to initialize the whole thing.
>
>Example from PyCrust:
>
> =
>
>>>>_("&Next")
>>>> =
>>>>
>Traceback (most recent call last):
> File "<input>", line 1, in ?
>NameError: name '_' is not defined
> =
>
>>>>lc =3D wx.Locale(wx.LANGUAGE_DEFAULT)
>>>>_("&Next")
>>>> =
>>>>
>Traceback (most recent call last):
> File "<input>", line 1, in ?
>NameError: name '_' is not defined
> =
>
>>>>import os
>>>>import gettext
>>>> =
>>>>
>... =
> =
>
>>>>localedir =3D os.path.join(wx.__path__[0], "locale")
>>>> =
>>>>
>... =
> =
>
>>>>langid =3D wx.LANGUAGE_DEFAULT # use OS default; or use LANGUAGE_JAP=
ANESE, etc.
>>>>domain =3D "wxstd" # the translation file is messages.mo
>>>> =
>>>>
>... =
> =
>
>>>>mylocale =3D wx.Locale(langid)
>>>>mytranslation =3D gettext.translation(domain, localedir,
>>>> =
>>>>
>... [mylocale.GetCanonicalName()], fallback =3D True)
> =
>
>>>>mytranslation.install()
>>>> =
>>>>
>... =
> =
>
>>>>_("&Next")
>>>> =
>>>>
>'&Weiter'
> =
>
>
>And I'm looking for a way to shorten this procedure.
>
>Second question:
>Ok, now the paths for the catalog for wxstd are initailized.
> =
>I'm looking for a convenient way to initialize a catalog file:
>For example: my App starte in c:\Eigene Dateien\python\drpython\drpython.py
>
>First: what would be a convenient place to locate the .mo file?
> =
>
convention is to store it in yourapp\locale\lang (lang is whatever =
languages you support (de, fr etc)
>Second: is it possible to use the (untranslated) file .po directly? (it do=
esn't seem to work)
> =
>
no, at least not that I know of.
>Third: What is the right way to initialize to use this catalog (in additio=
n to wxstd.mo)?
>
>(mo file is in the following location):
>c:\Eigene Dateien\python\drpython\locale\de\LC_MESSAGES\drpython.mo
>
>mytranslation =3D gettext.translation("drpython", os.path.abspath(os.curdi=
r) + '/locale', [mylocale.GetCanonicalName()], fallback =3D
>True)
>mytranslation.install()
>
>
>Many thanks, to Robin or whoever else can answer my question!! :)
> =
>
See attached small sample app for I18n which I did some time ago. Note =
that all "user" translation will switch immediately, but the "wx" =
translation you switch and have to restart the application.
Hope this helps
Werner
-------------- next part --------------
A non-text attachment was scrubbed...
Name: i18n.zip
Type: application/x-zip-compressed
Size: 35210 bytes
Desc: not available
Url : http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/20060=
814/d91ce5a5/i18n.bin
More information about the wxpython-users
mailing list