wxWizard, several question
28 answers - 753 bytes -

Hi friends,
Several question about wxWizard:
1. I have Wizard with several page, on a page is a three button 'Back',
'Next' and 'Cancel. I want create fully i18n application, but problem in
that the 'Back' and 'Next' but is untranslated and 'Cancel' is ok. How I
can translate this two button? I use it under Linux, this is anyhow
related to GTK/GNME i18n or ?
2. I want disable the 'Next' button on achieving some condition. How I
can make so?
Thanks for your help!
To unsubscribe, e-mail: wxPython-users-unsubscribe (AT) lists (DOT) wxwidgets.org
For additional commands, e-mail: wxPython-users-help (AT) lists (DOT) wxwidgets.org
No.1 | | 1085 bytes |
| 
Wed, 09 Aug 2006 19:39:36 +0700, Basil Shubin <bashu (AT) yandex (DOT) ruwrote:
>Hi friends,
>
>Several question about wxWizard:
>1. I have Wizard with several page, on a page is a three button 'Back',
>'Next' and 'Cancel. I want create fully i18n application, but problem in
>that the 'Back' and 'Next' but is untranslated and 'Cancel' is ok. How I
>can translate this two button? I use it under Linux, this is anyhow
>related to GTK/GNME i18n or ?
>2. I want disable the 'Next' button on achieving some condition. How I
>can make so?
>
>Thanks for your help!
Hello,
searching the archives, I found this question asked more than one time.
Robin answered:
2) wizard.FindWindowById(wx.ID_FRWARD).Disable()
for 1)
same procedure to get the button as in 1)
wizard.FindWindowById(wx.ID_FRWARD).SetLabel("Naechste") (example for german)
here you can use your I18N String.
No.2 | | 256 bytes |
| 
Wed, 09 Aug 2006 17:32:42 +0200, Franz Steinhaeusler <franz.steinhaeusler (AT) gmx (DOT) atwrote:
>for 1)
>same procedure to get the button as in 1)
>
same procedure to get the button as in 2) I meant.
No.3 | | 1113 bytes |
| 
Wed, 09 Aug 2006 19:39:36 +0700, Basil Shubin <bashu (AT) yandex (DOT) ruwrote:
>1. I have Wizard with several page, on a page is a three button 'Back',
>'Next' and 'Cancel. I want create fully i18n application, but problem in
>that the 'Back' and 'Next' but is untranslated and 'Cancel' is ok. How I
>can translate this two button? I use it under Linux, this is anyhow
>related to GTK/GNME i18n or ?
Wed, Aug 09, 2006 at 05:32:42PM +0200, Franz Steinhaeusler wrote:
wizard.FindWindowById(wx.ID_FRWARD).SetLabel("Naechste") (example for german)
here you can use your I18N String.
While this does work the P probably wonders why the "Next"
and "Back" buttons are not translated even though locale and
gettext are properly activated (other buttons are, the
wizard buttons are not). I have observed this before, too.
Pretty likely this is either just a simple omission in the
appropriate *.po file or a missing _() around the default
button labels.
Karsten
No.4 | | 1431 bytes |
| 
Franz Steinhaeusler wrote:
Wed, 09 Aug 2006 19:39:36 +0700, Basil Shubin <bashu (AT) yandex (DOT) ruwrote:
>Hi friends,
>>
>Several question about wxWizard:
>1. I have Wizard with several page, on a page is a three button 'Back',
>'Next' and 'Cancel. I want create fully i18n application, but problem in
>that the 'Back' and 'Next' but is untranslated and 'Cancel' is ok. How I
>can translate this two button? I use it under Linux, this is anyhow
>related to GTK/GNME i18n or ?
>2. I want disable the 'Next' button on achieving some condition. How I
>can make so?
>>
>Thanks for your help!
Hello,
searching the archives, I found this question asked more than one time.
Robin answered:
2) wizard.FindWindowById(wx.ID_FRWARD).Disable()
for 1)
same procedure to get the button as in 1)
wizard.FindWindowById(wx.ID_FRWARD).SetLabel("Naechste") (example for german)
here you can use your I18N String.
And what is ID for 'Finish' button? Where to look?
To unsubscribe, e-mail: wxPython-users-unsubscribe (AT) lists (DOT) wxwidgets.org
For additional commands, e-mail: wxPython-users-help (AT) lists (DOT) wxwidgets.org
No.5 | | 539 bytes |
| 
Sat, 12 Aug 2006 12:34:28 +0700, Basil Shubin <bashu (AT) yandex (DOT) ruwrote:
>[]
>And what is ID for 'Finish' button? Where to look?
wx.ID_CANCEL (?) and for Help wx.ID_HELP
You are right that is not so easy to find out.
For such cases, I have a copy of wxwidgets on my
harddisk, to look for such thing, which are wrapped
in wxPython then.
But maybe you can get this by GetChildren, then looking for the ID's
for the buttons with GetID, IIRC.
No.6 | | 1321 bytes |
| 
Sat, 12 Aug 2006 09:46:58 +0200, Franz S <franz.steinhaeusler (AT) gmx (DOT) atwrote:
Sat, 12 Aug 2006 12:34:28 +0700, Basil Shubin <bashu (AT) yandex (DOT) ruwrote:
>
>>[]
>>And what is ID for 'Finish' button? Where to look?
>
>wx.ID_CANCEL (?) and for Help wx.ID_HELP
>
>You are right that is not so easy to find out.
>For such cases, I have a copy of wxwidgets on my
>harddisk, to look for such thing, which are wrapped
>in wxPython then.
>
>But maybe you can get this by GetChildren, then looking for the ID's
>for the buttons with GetID, IIRC.
Sorry, I confused the Cancel with the Finish Button.
I don't know a solution, because in wxWidgets it is set directly.
bool wxWizard::ShowPage:
bool hasNext = HasNextPage(m_page);
if ( btnLabelWasNext != hasNext )
{
// need to update
if (btnLabelWasNext)
m_btnNext->SetLabel(_("&Finish"));
else
m_btnNext->SetLabel(_("&Next >"));
}
There is also the problem, if you come to the last page (with the button "Finish),
then, if you go back, there is again the original "Next >" text.
Maybe another one knows a solution.
No.7 | | 486 bytes |
| 
Sat, Aug 12, 2006 at 10:26:41AM +0200, Franz S wrote:
bool wxWizard::ShowPage:
bool hasNext = HasNextPage(m_page);
if ( btnLabelWasNext != hasNext )
{
// need to update
if (btnLabelWasNext)
m_btnNext->SetLabel(_("&Finish"));
else
m_btnNext->SetLabel(_("&Next >"));
}
This snippet also tells us that untranslated button labels
are very likely simply missing from the translation file
(gettext catalog, I guess).
Karsten
No.8 | | 1881 bytes |
| 
Sat, 12 Aug 2006 10:26:41 +0200, Franz S <franz.steinhaeusler (AT) gmx (DOT) atwrote:
Sat, 12 Aug 2006 09:46:58 +0200, Franz S <franz.steinhaeusler (AT) gmx (DOT) atwrote:
>
>Sat, 12 Aug 2006 12:34:28 +0700, Basil Shubin <bashu (AT) yandex (DOT) ruwrote:
>>
So after playing around, I think, I got it. Example with german texts.
Easy to verify, if you modify the wizard.py in the demo directory.
(You can run it as standalone)
add this line (for example at the beginning of the file after import images):
import images
class MyWizard(wiz.Wizard):
def __init__(self, parent, title):
wiz.Wizardinit__(self, parent, -1, title, images.getWizTest1Bitmap())
self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, WizPageChanged)
self.FindWindowById(wx.ID_BACKWARD).SetLabel ("< &Z")
self.FindWindowById(wx.ID_CANCEL).SetLabel ("&Abbrechen")
def WizPageChanged(self, evt):
label = "&Weiter >"
if not self.HasNextPage(self.GetCurrentPage()):
label = "&Fertig"
self.FindWindowById(wx.ID_FRWARD).SetLabel (label)
change this two lines:
def RunSimpleWizard(self, evt):
# Create the wizard and the pages
wizard = MyWizard(self, "Simple Wizard") #here MyWizard
def RunDynamicWizard(self, evt):
# Create the wizard and the pages
#wizard = wx.PreWizard()
#wizard.SetExtraStyle(wx.WIZARD_EX_HELPBUTTN)
#wizard.Create(self, self.ID_wiz, "Simple Wizard",
# images.getWizTest1Bitmap())
wizard = MyWizard(self, "Dynamic Wizard") #here MyWizard
Robin, a small point:
It would be better in the demo (I'm not sure, if it is fixed already, because
I use 2.6.2.1) to distinguish between "Simple Wizard" and "Dynamic Wizard"
also in the Title Box in the Wizard Window.
No.9 | | 777 bytes |
| 
Sat, 12 Aug 2006 12:16:55 +0200, Karsten Hilbert <Karsten.Hilbert (AT) gmx (DOT) netwrote:
Sat, Aug 12, 2006 at 10:26:41AM +0200, Franz S wrote:
>
>bool wxWizard::ShowPage:
>
>bool hasNext = HasNextPage(m_page);
>if ( btnLabelWasNext != hasNext )
>{
>// need to update
>if (btnLabelWasNext)
>m_btnNext->SetLabel(_("&Finish"));
>else
>m_btnNext->SetLabel(_("&Next >"));
>}
>
>This snippet also tells us that untranslated button labels
>are very likely simply missing from the translation file
>(gettext catalog, I guess).
>
>Karsten
About that I also wondered, but in the po files, that strings
are translated. (?)
No.10 | | 296 bytes |
| 
Franz S wrote:
It would be better in the demo (I'm not sure, if it is fixed already, because
I use 2.6.2.1) to distinguish between "Simple Wizard" and "Dynamic Wizard"
also in the Title Box in the Wizard Window.
Thanks for pointing that out. A copy/paste error I imagine.
No.11 | | 1391 bytes |
| 
Karsten Hilbert wrote:
Sat, Aug 12, 2006 at 10:26:41AM +0200, Franz S wrote:
>bool wxWizard::ShowPage:
>
>bool hasNext = HasNextPage(m_page);
>if ( btnLabelWasNext != hasNext )
>{
>// need to update
>if (btnLabelWasNext)
>m_btnNext->SetLabel(_("&Finish"));
>else
>m_btnNext->SetLabel(_("&Next >"));
>}
This snippet also tells us that untranslated button labels
are very likely simply missing from the translation file
(gettext catalog, I guess).
that the message catalogs are not being found at runtime. I recently
discovered that the Windows installers are putting the message catalogs
in the wrong directory structure on Windows. So Franz and Basil, if you
are seeing these buttons not getting automatically translated on
windows, please try the following:
1. Go to your site-packages/wx-2.6-msw-*/wx/locale dir.
2. Look in the subdir corresponding to your language code. If there is
a LC_MESSAGES dir there, move the wxstd.mo file up one directory level
and then remove the LC_MESSAGES dir. In other words, the structure
should be locale/<lang>/wxstd.mo, not locale/<lang>/LC_MESSAGES/wxstd.mo.
3. Try running a Wizard again without manual translation and see if the
buttons are now translated for you.
No.12 | | 1114 bytes |
| 
Sat, Aug 12, 2006 at 11:42:51AM -0700, Robin Dunn wrote:
>This snippet also tells us that untranslated button labels
>are very likely simply missing from the translation file
>(gettext catalog, I guess).
that the message catalogs are not being found at runtime.
Ah, true enough !
I recently
discovered that the Windows installers are putting the message catalogs
in the wrong directory structure on Windows.
However, I am fairly sure I have seen this happen on Linux,
too.
Also, the thing is, only *some* of the buttons were
untranslated while other things (other buttons in the
wizard, other buttons in other dialogs) *were* translated.
Which seems to contradict the catalog-not-found theory.
When I see it re-occur I'll report to the list.
Despite all that wxPython is very nice and useful. We are
just now releasing the second version of GNUmed (a medical
practice management system) the frontend of which is written
in wxPython 2.6:
http://wiki.gnumed.de
Thanks,
Karsten
No.13 | | 1688 bytes |
| 
Sat, 12 Aug 2006 22:15:02 +0200, Franz S <franz.steinhaeusler (AT) gmx (DOT) atwrote:
>So for the wizard demo, I added the lines (to work with the Python gettext):
>
(I pasted this twice, so please forget this from here
>import images
>
>import os
>import gettext
>
>localedir = os.path.join(wxpath__[0], "locale")
>
>langid = wx.LANGUAGE_DEFAULT # use S default; or use LANGUAGE_JAPANESE, etc.
>domain = "wxstd" # the translation file is messages.mo
>
>mylocale = wx.Locale(langid)
>mytranslation = gettext.translation(domain, localedir,
[mylocale.GetCanonicalName()], fallback = True)
>mytranslation.install()
>
until here).
>(I think, this whole intro could be reduced to one or two lines,
>is there something provided in wxPython or wxWidgets as a command
>to use the local language?)
>
>For the first, put after import images (in the wizard sample):
>
>import images
>
>import os
>import gettext
>
>localedir = os.path.join(wxpath__[0], "locale")
>
>langid = wx.LANGUAGE_DEFAULT # use S default; or use LANGUAGE_JAPANESE, etc.
>domain = "wxstd" # the translation file is messages.mo
>
>mylocale = wx.Locale(langid)
>mytranslation = gettext.translation(domain, localedir,
[mylocale.GetCanonicalName()], fallback = True)
>mytranslation.install()
>
>
>
>For the second (wxWidgets):
No.14 | | 628 bytes |
| 
Sat, 12 Aug 2006 22:04:39 +0200, Karsten Hilbert <Karsten.Hilbert (AT) gmx (DOT) netwrote:
>[]
>
>Also, the thing is, only *some* of the buttons were
>untranslated while other things (other buttons in the
>wizard, other buttons in other dialogs) *were* translated.
>Which seems to contradict the catalog-not-found theory.
>[]
Karsten, do you refer to the common dialogs?
Then these are native dialogs on the operating system
and this are translated by the system, in other
words this issue have nothing to do with the text catalogs.
No.15 | | 3557 bytes |
| 
Sat, 12 Aug 2006 11:42:51 -0700, Robin Dunn <robin (AT) alldunn (DOT) comwrote:
>Karsten Hilbert wrote:
>Sat, Aug 12, 2006 at 10:26:41AM +0200, Franz S wrote:
>
bool wxWizard::ShowPage:
bool hasNext = HasNextPage(m_page);
if ( btnLabelWasNext != hasNext )
{
// need to update
if (btnLabelWasNext)
m_btnNext->SetLabel(_("&Finish"));
else
m_btnNext->SetLabel(_("&Next >"));
}
>
>This snippet also tells us that untranslated button labels
>are very likely simply missing from the translation file
>(gettext catalog, I guess).
>
that the message catalogs are not being found at runtime. I recently
>discovered that the Windows installers are putting the message catalogs
>in the wrong directory structure on Windows. So Franz and Basil, if you
>are seeing these buttons not getting automatically translated on
>windows, please try the following:
>
>1. Go to your site-packages/wx-2.6-msw-*/wx/locale dir.
>
>2. Look in the subdir corresponding to your language code. If there is
>a LC_MESSAGES dir there, move the wxstd.mo file up one directory level
>and then remove the LC_MESSAGES dir. In other words, the structure
>should be locale/<lang>/wxstd.mo, not locale/<lang>/LC_MESSAGES/wxstd.mo.
>
>3. Try running a Wizard again without manual translation and see if the
>buttons are now translated for you.
Robin, it makes no difference. I works after applying the sample below for BTH cases.
Verifying it with wiki (and taking this sample as base and changed a little bit),
I saw, I have to initialize the gettext system.
There are this two possibilities:
1) use wxWidgets gettext system
2) the python gettext system, which didn't work without modification.
So for the wizard demo, I added the lines (to work with the Python gettext):
import images
import os
import gettext
localedir = os.path.join(wxpath__[0], "locale")
langid = wx.LANGUAGE_DEFAULT # use S default; or use LANGUAGE_JAPANESE, etc.
domain = "wxstd" # the translation file is messages.mo
mylocale = wx.Locale(langid)
mytranslation = gettext.translation(domain, localedir,
[mylocale.GetCanonicalName()], fallback = True)
mytranslation.install()
(I think, this whole intro could be reduced to one or two lines,
is there something provided in wxPython or wxWidgets as a command
to use the local language?)
For the first, put after import images (in the wizard sample):
import images
import os
import gettext
localedir = os.path.join(wxpath__[0], "locale")
langid = wx.LANGUAGE_DEFAULT # use S default; or use LANGUAGE_JAPANESE, etc.
domain = "wxstd" # the translation file is messages.mo
mylocale = wx.Locale(langid)
mytranslation = gettext.translation(domain, localedir,
[mylocale.GetCanonicalName()], fallback = True)
mytranslation.install()
For the second (wxWidgets):
# Set locale for wxWidgets
mylocale = wx.Locale(langid)
(localedir)
mylocale.AddCatalog(domain)
print wx.GetTranslation("Next")
Please correct me, if I said something wrong, or if I understood something
wrong (I'm pretty sure about that). ;)
Also the wxpath__[0] is ugly, and I'm sure, there is another better way!
No.16 | | 674 bytes |
| 
Sat, Aug 12, 2006 at 10:20:12PM +0200, Franz S wrote:
Karsten, do you refer to the common dialogs?
Ja.
Then these are native dialogs on the operating system
and this are translated by the system, in other
words this issue have nothing to do with the text catalogs.
True. That, of course, explains that part.
BTW, in our application we do not explicitely activate
gettext via the wxPython methods. We do activate it from the
Python side directly. Which seems to work fine. I'll have to
re-check the wizard applying the clue you provided above:
that native dialogs are, of course, translated at the S
level.
Karsten
No.17 | | 1284 bytes |
| 
Franz S wrote:
Robin, it makes no difference. I works after applying the sample below for BTH cases.
Verifying it with wiki (and taking this sample as base and changed a little bit),
I saw, I have to initialize the gettext system.
There are this two possibilities:
1) use wxWidgets gettext system
Ah, yes. I forgot to mention that the wx.Locale needs to be created.
This is how wxWidgets gets its strings from its message catalog.
localedir = os.path.join(wxpath__[0], "locale")
# Set locale for wxWidgets
mylocale = wx.Locale(langid)
(localedir)
This shouldn't be necessary on Windows, this path is added when wx is
imported. the other platforms the standard locations for message
catalogs are searched automatically as well.
mylocale.AddCatalog(domain)
Nor this. The 'wxstd' catalog is already searched for.
PyShell 0.9.5 - The Flakiest Python Shell
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
import wx
wx.VERSIN
(2, 6, 3, 3, '')
lc = wx.Locale(wx.LANGUAGE_FRENCH)
wx.GetTranslation('&Next')
u'&Suivant'
No.18 | | 1773 bytes |
| 
Sat, 12 Aug 2006 15:15:04 -0700, Robin Dunn <robin (AT) alldunn (DOT) comwrote:
>Franz S wrote:
>
>
>Robin, it makes no difference. I works after applying the sample below for BTH cases.
>
>Verifying it with wiki (and taking this sample as base and changed a little bit),
>I saw, I have to initialize the gettext system.
>
>There are this two possibilities:
>1) use wxWidgets gettext system
>
>Ah, yes. I forgot to mention that the wx.Locale needs to be created.
>This is how wxWidgets gets its strings from its message catalog.
>
>
>localedir = os.path.join(wxpath__[0], "locale")
>
># Set locale for wxWidgets
>mylocale = wx.Locale(langid)
>(localedir)
>
>This shouldn't be necessary on Windows, this path is added when wx is
>imported. the other platforms the standard locations for message
>catalogs are searched automatically as well.
>
>mylocale.AddCatalog(domain)
>
>Nor this. The 'wxstd' catalog is already searched for.
>
>
PyShell 0.9.5 - The Flakiest Python Shell
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)]
>on win32
Type "help", "copyright", "credits" or "license" for more information.
import wx
wx.VERSIN
(2, 6, 3, 3, '')
lc = wx.Locale(wx.LANGUAGE_FRENCH)
wx.GetTranslation('&Next')
u'&Suivant'
Yes, but in wxWidgets, almost all strings are there using
the _("&Next") and not wx.GetTranslation("%Next")
I would be interested to know the shortest way to get this translation.
Thanks again!
No.19 | | 2221 bytes |
| 
Hi Robin,
I wondered, in the Demo it worked and not in Pycrust or another application.
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 = 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 = os.path.join(wxpath__[0], "locale")
langid = wx.LANGUAGE_DEFAULT # use S default; or use LANGUAGE_JAPANESE, etc.
domain = "wxstd" # the translation file is messages.mo
mylocale = wx.Locale(langid)
mytranslation = gettext.translation(domain, localedir,
[mylocale.GetCanonicalName()], fallback = True)
mytranslation.install()
_("&Next")
'&Weiter'
And I'm looking for a way to shorten this procedure.
Second question:
, 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?
Second: is it possible to use the (untranslated) file .po directly? (it doesn't seem to work)
Third: What is the right way to initialize to use this catalog (in addition to wxstd.mo)?
(mo file is in the following location):
c:\Eigene Dateien\python\drpython\locale\de\LC_MESSAGES\drpy thon.mo
mytranslation = gettext.translation("drpython", os.path.abspath(os.curdir) + '/locale', [mylocale.GetCanonicalName()], fallback =
True)
mytranslation.install()
Many thanks, to Robin or whoever else can answer my question!! :)
No.20 | | 3408 bytes |
| 
Hi Franz,
Have you seen the wiki pages?
%28i18n%29
Franz S wrote:
>Hi Robin,
>
>I wondered, in the Demo it worked and not in Pycrust or another application.
>
>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 = 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 = os.path.join(wxpath__[0], "locale")
langid = wx.LANGUAGE_DEFAULT # use S default; or use LANGUAGE_JAPANESE, etc.
domain = "wxstd" # the translation file is messages.mo
mylocale = wx.Locale(langid)
mytranslation = gettext.translation(domain, localedir,
[mylocale.GetCanonicalName()], fallback = True)
mytranslation.install()
("&Next")
>'&Weiter'
>
>
>And I'm looking for a way to shorten this procedure.
>
>Second question:
>, 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 doesn'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 addition to wxstd.mo)?
>
>(mo file is in the following location):
>c:\Eigene Dateien\python\drpython\locale\de\LC_MESSAGES\drpy thon.mo
>
>mytranslation = gettext.translation("drpython", os.path.abspath(os.curdir) + '/locale', [mylocale.GetCanonicalName()], fallback =
>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
To unsubscribe, e-mail: wxPython-users-unsubscribe (AT) lists (DOT) wxwidgets.org
For additional commands, e-mail: wxPython-users-help (AT) lists (DOT) wxwidgets.org
No.21 | | 2564 bytes |
| 
Mon, 14 Aug 2006 11:06:11 +0200, "Werner F. Bruhin" <werner.bruhin (AT) free (DOT) frwrote:
>Hi Franz,
>
>Have you seen the wiki pages?
>
>
>%28i18n%29
>
Hi Werner,
yes, I know them, and these are good explanations.
I'm firstly looking for a code small as possible
to initialize the program to use the native Language.
Best a oneliner:
install_default_lang() or so.
>Franz S wrote:
>
>>Second question:
>>, 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)
Yes, I made this so in my TestApp.
>
>>Second: is it possible to use the (untranslated) file .po directly? (it doesn't seem to work)
>
>>
>no, at least not that I know of.
, but what speaks against that to not make it possible.
(No need of transorming that to .mo file) and faster changing
the text containts.
>
>>Third: What is the right way to initialize to use this catalog (in addition to wxstd.mo)?
>>
>>(mo file is in the following location):
>>c:\Eigene Dateien\python\drpython\locale\de\LC_MESSAGES\drpy thon.mo
>>
>>mytranslation = gettext.translation("drpython", os.path.abspath(os.curdir) + '/locale', [mylocale.GetCanonicalName()], fallback =
>>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.
Thank you, I give it a look.
>
>Hope this helps
>Werner
No.22 | | 385 bytes |
| 
Franz S wrote:
Yes, but in wxWidgets, almost all strings are there using
the _("&Next") and not wx.GetTranslation("%Next")
I would be interested to know the shortest way to get this translation.
_(foo) is a C macro that expands to wxGetTranslation(foo), so they are
equivalent to each other. In Python you could do something like
_ = wx.GetTranslation
No.23 | | 2826 bytes |
| 
Franz S wrote:
Example from PyCrust:
_("&Next")
Traceback (most recent call last):
File "<input>", line 1, in ?
NameError: name '_' is not defined
lc = 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 = os.path.join(wxpath__[0], "locale")
langid = wx.LANGUAGE_DEFAULT # use S default; or use LANGUAGE_JAPANESE, etc.
domain = "wxstd" # the translation file is messages.mo
mylocale = wx.Locale(langid)
mytranslation = gettext.translation(domain, localedir,
[mylocale.GetCanonicalName()], fallback = True)
mytranslation.install()
_("&Next")
'&Weiter'
And I'm looking for a way to shorten this procedure.
_ is just a shortcut to a function (typically) and so you just need to
give it a definition, or set it to some existing function. For example:
_ = wx.GetTranslation
lc = wx.Locale(wx.LANGUAGE_FRENCH)
_("Next")
u'Suivant'
del lc
lc = wx.Locale(wx.LANGUAGE_JAPANESE)
_("Next")
u'\u6b21\u3078'
you could set it globally like the gettext module does by putting it
in the __builtin__ module:
import __builtin__
__builtindict__['_'] = wx.GetTranslation
Second question:
, 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?
It depends on the platform, as each has their standard locations for .mo
files, although I think that it always looks in the current working
directory first. You can also add additional directories to the search
path by calling
Second: is it possible to use the (untranslated) file .po directly? (it doesn't seem to work)
Yes and No. Normally you can't, but if you really wanted to you could
write a function that can parse the .po files and pull the translations
out for you, and then assign that function to _, but only your code that
uses that function would be using the .po file instead of the .mo file
Third: What is the right way to initialize to use this catalog (in addition to wxstd.mo)?
(mo file is in the following location):
c:\Eigene Dateien\python\drpython\locale\de\LC_MESSAGES\drpy thon.mo
lc.AddCatalog('drpython')
BTW, I think that on Windows it will not look in
<prefix>/<lang>/LC_MESSAGES like it does on the other platforms, just
<prefix>/<lang>.
No.24 | | 609 bytes |
| 
Mon, 14 Aug 2006 10:17:03 -0700, Robin Dunn <robin (AT) alldunn (DOT) comwrote:
>Franz S wrote:
>
>
>Yes, but in wxWidgets, almost all strings are there using
>the _("&Next") and not wx.GetTranslation("%Next")
>
>I would be interested to know the shortest way to get this translation.
>
>_(foo) is a C macro that expands to wxGetTranslation(foo), so they are
>equivalent to each other. In Python you could do something like
>
>_ = wx.GetTranslation
Thank you very much Robin, how easy! *blush* :)
No.25 | | 5012 bytes |
| 
Mon, 14 Aug 2006 10:18:42 -0700, Robin Dunn <robin (AT) alldunn (DOT) comwrote:
>Franz S wrote:
>
>Example from PyCrust:
>
_("&Next")
>Traceback (most recent call last):
>File "<input>", line 1, in ?
>NameError: name '_' is not defined
lc = 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 = os.path.join(wxpath__[0], "locale")
langid = wx.LANGUAGE_DEFAULT # use S default; or use LANGUAGE_JAPANESE, etc.
domain = "wxstd" # the translation file is messages.mo
mylocale = wx.Locale(langid)
mytranslation = gettext.translation(domain, localedir,
>[mylocale.GetCanonicalName()], fallback = True)
mytranslation.install()
_("&Next")
>'&Weiter'
>
>And I'm looking for a way to shorten this procedure.
>
>_ is just a shortcut to a function (typically) and so you just need to
>give it a definition, or set it to some existing function. For example:
>
_ = wx.GetTranslation
lc = wx.Locale(wx.LANGUAGE_FRENCH)
_("Next")
u'Suivant'
del lc
Hi Robin,
this del lc is obviously need, because without this the tranlation reverts
to the default language (english).
But why is this so, or the more important, how do I know, that I have to delete
this instance and cannot rely on the garbage collector?
lc = wx.Locale(wx.LANGUAGE_JAPANESE)
_("Next")
u'\u6b21\u3078'
--
you could set it globally like the gettext module does by putting it
>in the __builtin__ module:
>
import __builtin__
__builtindict__['_'] = wx.GetTranslation
Ah, I see.
>
>
>Second question:
>, 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?
>
>It depends on the platform, as each has their standard locations for .mo
>files, although I think that it always looks in the current working
>directory first. You can also add additional directories to the search
>path by calling
>
Cool!!!
I think, I have the best solution (only four lines to initialize the
wxPython (wxWidgets) Standard translation file and the user
translations need by that specific App (here drPython).
The language file is located under:
c:\Eigene Dateien\python\drpython\locale\de\LC_MESSAGES\drpy thon.mo
where c:\Eigene Dateien\python\drpython\ is the directory,
where DrPython is launched.
Voila:, so simple in reality :-)
lc = wx.Locale(wx.LANGUAGE_DEFAULT) #here the wxstd.mo file is already fond and used
_ = wx.GetTranslation
lc.AddCatalogLookupPathPrefix('locale')
lc.AddCatalog('drpython')
#lc.AddCatalog('drpython_test2') #works too
#print _("&Advanced") #for testing drpython.mo
#print _("&Next") #for testing wxstd.mo
or if you need another path:
lc.AddCatalogLookupPathPrefix(<your path+ '/locale')
>Second: is it possible to use the (untranslated) file .po directly? (it doesn't seem to work)
>
>Yes and No. Normally you can't, but if you really wanted to you could
>write a function that can parse the .po files and pull the translations
>out for you, and then assign that function to _, but only your code that
>uses that function would be using the .po file instead of the .mo file
>
>Third: What is the right way to initialize to use this catalog (in addition to wxstd.mo)?
>
>(mo file is in the following location):
>c:\Eigene Dateien\python\drpython\locale\de\LC_MESSAGES\drpy thon.mo
>
>
>lc.AddCatalog('drpython')
>
>BTW, I think that on Windows it will not look in
><prefix>/<lang>/LC_MESSAGES like it does on the other platforms, just
><prefix>/<lang>.
No, it works for me, because my mo file is in
c:\Eigene Dateien\python\drpython\locale\de\LC_MESSAGES\drpy thon.mo
and the four lines above cooperate with this directory.
But the same code works for:
c:\Eigene Dateien\python\drpython\locale\de\drpython.mo
But if you think, the right location is this path, I'll put it here.
Many thanks for your hints!
No.26 | | 2330 bytes |
| 
Franz S wrote:
Mon, 14 Aug 2006 10:18:42 -0700, Robin Dunn <robin (AT) alldunn (DOT) comwrote:
>_ is just a shortcut to a function (typically) and so you just need to
>give it a definition, or set it to some existing function. For example:
>>
>_ = wx.GetTranslation
>lc = wx.Locale(wx.LANGUAGE_FRENCH)
>_("Next")
>u'Suivant'
>del lc
Hi Robin,
this del lc is obviously need, because without this the tranlation reverts
to the default language (english).
But why is this so, or the more important, how do I know, that I have to delete
this instance and cannot rely on the garbage collector?
This is a tricky case. The root of the problem is that the C++ wxLocale
destructor resets the current locale to what was current when the
wxLocale was constructed. When you combine this with the Python
reference counter/garbage collector then you end up with the following
sequence of events when you do this:
lc = wx.Locale(wx.LANGUAGE_FRENCH)
lc = wx.Locale(wx.LANGUAGE_SPANISH)
1. the french wx.Locale is constructed, saving the current locale (None)
2. the locale is assigned to the new variable lc
3. the spanish locale is constructed, saving the current locale (French)
4. the locale is assigned to lc
5. the object formerly referenced by lc is garbage collected because its
ref-count has dropped to zero
6. the C++ wxLocale destructor is called, and it restores the wxLocale
that was current when it was created (None)
>BTW, I think that on Windows it will not look in
><prefix>/<lang>/LC_MESSAGES like it does on the other platforms, just
><prefix>/<lang>.
No, it works for me, because my mo file is in
c:\Eigene Dateien\python\drpython\locale\de\LC_MESSAGES\drpy thon.mo
and the four lines above cooperate with this directory.
But the same code works for:
c:\Eigene Dateien\python\drpython\locale\de\drpython.mo
But if you think, the right location is this path, I'll put it here.
If it works then don't worry about it, I may have just misread or
misremembered the code.
No.27 | | 2428 bytes |
| 
Mon, 14 Aug 2006 18:58:05 -0700, Robin Dunn <robin (AT) alldunn (DOT) comwrote:
>[]
>
>Hi Robin,
>
>this del lc is obviously need, because without this the tranlation reverts
>to the default language (english).
>
>But why is this so, or the more important, how do I know, that I have to delete
>this instance and cannot rely on the garbage collector?
>
>This is a tricky case. The root of the problem is that the C++ wxLocale
>destructor resets the current locale to what was current when the
>wxLocale was constructed. When you combine this with the Python
>reference counter/garbage collector then you end up with the following
>sequence of events when you do this:
>
>lc = wx.Locale(wx.LANGUAGE_FRENCH)
>lc = wx.Locale(wx.LANGUAGE_SPANISH)
>
>
>1. the french wx.Locale is constructed, saving the current locale (None)
>
>2. the locale is assigned to the new variable lc
>
>3. the spanish locale is constructed, saving the current locale (French)
>
>4. the locale is assigned to lc
>
>5. the object formerly referenced by lc is garbage collected because its
>ref-count has dropped to zero
>
>6. the C++ wxLocale destructor is called, and it restores the wxLocale
>that was current when it was created (None)
>
Thank you for your explanation. Maybe this is worth an entry
in a wxPython wiki page like "Possible pitfalls". ;)
BTW, I think that on Windows it will not look in
<prefix>/<lang>/LC_MESSAGES like it does on the other platforms, just
<prefix>/<lang>.
>
>No, it works for me, because my mo file is in
>c:\Eigene Dateien\python\drpython\locale\de\LC_MESSAGES\drpy thon.mo
>
>and the four lines above cooperate with this directory.
>
>But the same code works for:
>c:\Eigene Dateien\python\drpython\locale\de\drpython.mo
>
>But if you think, the right location is this path, I'll put it here.
>
>If it works then don't worry about it, I may have just misread or
>misremembered the code.
, I like it more to put them in
c:\Eigene Dateien\python\drpython\locale\de\drpython.mo, so it looks
not so scattered.
No.28 | | 2428 bytes |
| 
Mon, 14 Aug 2006 18:58:05 -0700, Robin Dunn <robin (AT) alldunn (DOT) comwrote:
>[]
>
>Hi Robin,
>
>this del lc is obviously need, because without this the tranlation reverts
>to the default language (english).
>
>But why is this so, or the more important, how do I know, that I have to delete
>this instance and cannot rely on the garbage collector?
>
>This is a tricky case. The root of the problem is that the C++ wxLocale
>destructor resets the current locale to what was current when the
>wxLocale was constructed. When you combine this with the Python
>reference counter/garbage collector then you end up with the following
>sequence of events when you do this:
>
>lc = wx.Locale(wx.LANGUAGE_FRENCH)
>lc = wx.Locale(wx.LANGUAGE_SPANISH)
>
>
>1. the french wx.Locale is constructed, saving the current locale (None)
>
>2. the locale is assigned to the new variable lc
>
>3. the spanish locale is constructed, saving the current locale (French)
>
>4. the locale is assigned to lc
>
>5. the object formerly referenced by lc is garbage collected because its
>ref-count has dropped to zero
>
>6. the C++ wxLocale destructor is called, and it restores the wxLocale
>that was current when it was created (None)
>
Thank you for your explanation. Maybe this is worth an entry
in a wxPython wiki page like "Possible pitfalls". ;)
BTW, I think that on Windows it will not look in
<prefix>/<lang>/LC_MESSAGES like it does on the other platforms, just
<prefix>/<lang>.
>
>No, it works for me, because my mo file is in
>c:\Eigene Dateien\python\drpython\locale\de\LC_MESSAGES\drpy thon.mo
>
>and the four lines above cooperate with this directory.
>
>But the same code works for:
>c:\Eigene Dateien\python\drpython\locale\de\drpython.mo
>
>But if you think, the right location is this path, I'll put it here.
>
>If it works then don't worry about it, I may have just misread or
>misremembered the code.
, I like it more to put them in
c:\Eigene Dateien\python\drpython\locale\de\drpython.mo, so it looks
not so scattered.