wxLocale, xrc and i18n with wxPython

Hi,

I'm having trouble getting any kind of gettext to work with .xrc files. I've
tried several things, but the documentation is, as usual, sparse to the point
of useless (to people like me who haven't done this before). I tried this:
L = wxLocale()
L.Init("de_DE")
L.AddCatalog("lang/de_DE")
_ = L.GetString

which didn't work. L.Init() always returns false

I've tried installing gettext, but that won't translate .xrc files. So what's
the trick?

Dave

Hi,

Dave Richards wrote:

haven't done this before). I tried this: L = wxLocale()
L.Init("de_DE")
L.AddCatalog("lang/de_DE")
_ = L.GetString

which didn't work. L.Init() always returns false

Init returns false e.g. when it can't find wxstd.mo. Is it installed?

I've tried installing gettext, but that won't translate .xrc files.

What do you mean?

VS

···

--
PGP key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x465264C9

Vaclav Slavik wrote:

Hi,

Dave Richards wrote:

haven't done this before). I tried this: L = wxLocale()
L.Init("de_DE")
L.AddCatalog("lang/de_DE")
_ = L.GetString

which didn't work. L.Init() always returns false

Init returns false e.g. when it can't find wxstd.mo. Is it installed?

I've got a task on my ToDo list for 2.4.1 that I've been meaning to ask you about. Where should the .mo files go on Windows?

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

I tried gettext.install("myapp", "/path/to/my/locales")
and it works great for my normal gui code using _(), but any dialogs I
load from .xrc files are not automatically translated by wxPython /
gettext.

My question is: how do I set up application-wide translation of xrc
files using gettext / wxLocale / whatever?

wxLocale.Init() always returns false. I have tried the following
locales: "de", "de_DE"

wxstd.mo is installed in
/usr/share/wxGTK2.3.2/locale/de/LC_MESSAGES/wxstd.mo

Can somebody give me a simple - but clear - example of translating
dynamically loaded xrc resources or point me to one?

Thanks,

Dave

···

On (18/02/03 20:14), Vaclav Slavik wrote:

> I've tried installing gettext, but that won't translate .xrc files.

What do you mean?

Hi,

Robin Dunn wrote:

I've got a task on my ToDo list for 2.4.1 that I've been meaning to
ask you about. Where should the .mo files go on Windows?

By default in $LC_PATH (if set) or in current directory
(./${lang}/LC_MESSAGES/wxstd.mo). Or in directory added by the app
using wxLocale::AddCatalogLookupPathPrefix (I do this in poEdit). It
should probably use app's data directory by default (something that
we don't have the API for yet).

Perhaps wxPython could call wxLocale_AddCatalogLookupPathPrefix itself
and point wxLocale to some directory in site-packages/wxPython?

Regards,
Vaclav

···

--
PGP key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x465264C9

Hi,

Dave Richards wrote:

wxstd.mo is installed in
/usr/share/wxGTK2.3.2/locale/de/LC_MESSAGES/wxstd.mo

Than wxLocale indeed can't find the catalog (and hence returned
false), because it is a weird location. How did you end up with such
files layout? wxWindows looks for catalogs in ${prefix}/share/locale,
where ${prefix} is value you used in --prefix argument to configure
(and is /usr/local by default) or the value of WXPREFIX environment
variable if set. You'll have to call
wxLocale_AddCatalogLookupPathPrefix("/usr/share/wxGTK2.3.2/locale")
before wxLocale.Init if you want to run wxWindows in this setup.

Can somebody give me a simple - but clear - example of translating
dynamically loaded xrc resources or point me to one?

They are always translated automatically, if you provide a catalog
with translations (wxrc can generate fake C file that you can pass to
xgettext to get a .po file) and if you use wxXRC_USE_LOCALE flag when
constructing wxXmlResource (this is the defaut).

Regards,
Vaclav

···

--
PGP key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x465264C9

Vaclav Slavik wrote:

Perhaps wxPython could call wxLocale_AddCatalogLookupPathPrefix itself and point wxLocale to some directory in site-packages/wxPython?

Yep...

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

You'll have to call
wxLocale_AddCatalogLookupPathPrefix("/usr/share/wxGTK2.3.2/locale")
before wxLocale.Init if you want to run wxWindows in this setup.

Thank you very much. I have been beating my brains over how the hell I
was supposed to add my own files to the path - the manual says
wxLocale.AddCatalogLookupPathPrefix(), which doesn't exists. Somebody
really should write this kind of thing in the manual...

They are always translated automatically, if you provide a catalog
with translations (wxrc can generate fake C file that you can pass to
xgettext to get a .po file) and if you use wxXRC_USE_LOCALE flag when
constructing wxXmlResource (this is the defaut).

This much I had gleaned from the documentation, it just doesn't seem to
be working for me. Armed with the information from your email, I
reinstalled wxPython (the funny paths are due to the Mandrake RPMS) from
the www.wxpython.org source RPMS. It put my locales in
/usr/lib/wxPython/share/locale. So, I add this to the lookup path, but
it still won't work:

from wxPython.wx import *
L = wxLocale()
wxLocale_AddCatalogLookupPathPrefix("/usr/lib/wxPython/share/locale")
L.Init("de")

0

L.Init("en")

0

L.Init("deutsch")

0

L.Init("Deutsch")

0

L.Init(wxLANGUAGE_GERMAN)

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
    File "/usr/lib/python2.2/site-packages/wxPython/fonts.py", line 318,
    in Init
        val = apply(fontsc.wxLocale_Init,(self,) + _args, _kwargs)
        TypeError: String or Unicode type required

I just don't see what Im missing here, and I really don't want to have
to rewrite all my dialogs by hand because I can't get wxLocale to work.
Any ideas?

Thanks
Dave

Hi,

Dave Richards wrote:

Thank you very much. I have been beating my brains over how the
hell I was supposed to add my own files to the path - the manual
says wxLocale.AddCatalogLookupPathPrefix(), which doesn't exists.
Somebody really should write this kind of thing in the manual...

That's strange, I thought it must be mentioned somewhere, this is what
wxPython uses for all C++ static methods...

seem to be working for me. Armed with the information from your
email, I reinstalled wxPython (the funny paths are due to the
Mandrake RPMS)

I'll check if they still do it with wxGTK-2.4.0 RPM and if they do,
I'll complain about it.

L.Init("de")
0
>>> L.Init("en")
0
>>> L.Init("deutsch")
0
>>> L.Init("Deutsch")
0

Neither of these could work, please see wxLocale.Init documentation.
You are using the deprecated form here, where first argument (the
only one you give) is only descriptive. You'd have to use something
like Init("Deutch", "de", "de_DE") (the 3rd argument is plaform
specific!). Please don't use it,

>>> L.Init(wxLANGUAGE_GERMAN)

...use this one instead (it is supposed to work, there must be some
problem in wxPython).

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
    File "/usr/lib/python2.2/site-packages/wxPython/fonts.py", line
318, in Init
        val = apply(fontsc.wxLocale_Init,(self,) + _args, _kwargs)
        TypeError: String or Unicode type required

This one's for Robin...

I just don't see what Im missing here,

You haven't yet initialized wxLocale, see above.

Regards,
Vaclav

···

--
PGP key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x465264C9

That's strange, I thought it must be mentioned somewhere, this is what
wxPython uses for all C++ static methods...

It may well be, but I don't know any C++, and wouldn't necessarily
recognise a static function anyway.

> >>> L.Init(wxLANGUAGE_GERMAN)

...use this one instead (it is supposed to work, there must be some
problem in wxPython).

> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "/usr/lib/python2.2/site-packages/wxPython/fonts.py", line
> 318, in Init
> val = apply(fontsc.wxLocale_Init,(self,) + _args, _kwargs)
> TypeError: String or Unicode type required

This one's for Robin...

well robin? can you help?

dave

Vaclav Slavik wrote:

L.Init(wxLANGUAGE_GERMAN)

...use this one instead (it is supposed to work, there must be some problem in wxPython).

Traceback (most recent call last):
File "<stdin>", line 1, in ?
   File "/usr/lib/python2.2/site-packages/wxPython/fonts.py", line
318, in Init
       val = apply(fontsc.wxLocale_Init,(self,) + _args, _kwargs)
       TypeError: String or Unicode type required

This one's for Robin...

Hmm, I'm not sure why I didn't add that method (with a new name of course since it's overloaded and Python can't do that..) I'll do it for the next reelase. In the meantime it looks like you should be able to use that form with the constructor instead:

  locale = wxLocale(wxLANGUAGE_GERMAN)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Hi,

Robin Dunn wrote:

Hmm, I'm not sure why I didn't add that method (with a new name of
course since it's overloaded and Python can't do that..)

Boost.Python can do it and the new SWIG (1.3.17) has some support for
it, too :wink:
Anyway, it would be nice to have some reasonable name for this version
of Init, because it is the prefered one...

Vaclav

···

--
PGP key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x465264C9

Vaclav Slavik wrote:

Hi,

Robin Dunn wrote:

Hmm, I'm not sure why I didn't add that method (with a new name of
course since it's overloaded and Python can't do that..)

Boost.Python can do it and the new SWIG (1.3.17) has some support for it, too :wink:

Yeah, rub it in...

Anyway, it would be nice to have some reasonable name for this version of Init, because it is the prefered one...

Okay I didn't realize that. I could reverse which one gets the "Init" name, or just put a wrapper around it and do the overloading myself...

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Thanks a lot for your help guys. I got the bugger working finally. I've given
up on .xrc files for now, because I don't have wxrc and it won't compile, but
as they say, _("Das ist eine andere Geschichte und soll ein andermal erzählt
werden.").

Dave

···

On Thursday 20 February 2003 6:56 pm, Robin Dunn wrote:

  locale = wxLocale(wxLANGUAGE_GERMAN)