I want to display a SingleChoiceDialog on startup of my application in
which the user sets the desired language.
All languages are in gettext format and work.
Now:
Whenever I did this via "set the language to the OS language
automatically", I usually added a defaultOS languag and get the
translation part in the head of my app like this:
locale = wx.locale(wx.LANGUAGE_DEFAULT)
lang = locale.getdefaultlocale()[0]
APPDIR = os.getcwd()
LOCALEDIR = os.path.join(APPDIR, "locale", lang)
LOCALEDOMAIN = "i18n"
wx.SetDefaultPyEncoding("iso-8859-15")
_ = wx.GetTranslation
The problem now is that it seems like, once I initialise any frame, I
cannot change the locale part anymore, i.e. via a SingleChoice dialog,
popping up like a SplashScreen...
I do not want to change the language after startup,
The structure of my app is like this:
class My App....
def OnInit(self):
splash = MySplashScreen()
splash.Show()
return True
I had planned to display the language dialog in my SplashScreen class
before I call the main application frame:
lang_choice_dlg = wx.SingleChoiceDialog (self, 'Please select your
language', 'Language choice',
language_list,
wx.CHOICEDLG_STYLE
)
if lang_choice_dlg.ShowModal() == wx.ID_OK:
lang = (lang_choice_dlg.GetStringSelection())
lang_choice_dlg.Destroy()
APPDIR = os.getcwd()
LOCALEDIR = os.path.join(APPDIR, "locale", lang)
LOCALEDOMAIN = "i18n"
wx.SetDefaultPyEncoding("iso-8859-15")
_ = wx.GetTranslation
frame = AuiFrame(None)
frame.Show( )
This does not work ... anybody with a hint what I am missing? Is the
AuiFrame maybe translated before I actually call it? What can I do do
prevent it from this?
You need to create an instance of wx.Locale with the language choice, (and tell it where LOCALEDIR is and tell it to add your message catalog.) Also, you need to hold a reference to the locale object, otherwise it will restore to the previous settings when the locale object goes out of scope. For example:
Also, if you have more than one module you will probably want to set _ in builtins too so its value of wx.GetTranslation is seen everywhere in your application.
There are some examples in the wiki that may help for this, and also using Python's standard gettext instead of wx's if you would rather go that path.
···
On 4/23/12 6:35 AM, Tobias Weber wrote:
Hi,
I want to display a SingleChoiceDialog on startup of my application in
which the user sets the desired language.
All languages are in gettext format and work.
Now:
Whenever I did this via "set the language to the OS language
automatically", I usually added a defaultOS languag and get the
translation part in the head of my app like this:
locale = wx.locale(wx.LANGUAGE_DEFAULT)
lang = locale.getdefaultlocale()[0]
APPDIR = os.getcwd()
LOCALEDIR = os.path.join(APPDIR, "locale", lang)
LOCALEDOMAIN = "i18n"
wx.SetDefaultPyEncoding("iso-8859-15")
_ = wx.GetTranslation
The problem now is that it seems like, once I initialise any frame, I
cannot change the locale part anymore, i.e. via a SingleChoice dialog,
popping up like a SplashScreen...
I do not want to change the language after startup,
The structure of my app is like this:
class My App....
def OnInit(self):
splash = MySplashScreen()
splash.Show()
return True
I had planned to display the language dialog in my SplashScreen class
before I call the main application frame:
lang_choice_dlg = wx.SingleChoiceDialog (self, 'Please select your
language', 'Language choice',
language_list,
wx.CHOICEDLG_STYLE
)
if lang_choice_dlg.ShowModal() == wx.ID_OK:
lang = (lang_choice_dlg.GetStringSelection())
lang_choice_dlg.Destroy()
APPDIR = os.getcwd()
LOCALEDIR = os.path.join(APPDIR, "locale", lang)
LOCALEDOMAIN = "i18n"
wx.SetDefaultPyEncoding("iso-8859-15")
_ = wx.GetTranslation
frame = AuiFrame(None)
frame.Show( )
This does not work ... anybody with a hint what I am missing? Is the
AuiFrame maybe translated before I actually call it? What can I do do
prevent it from this?
Thanks - I already had this but did not handle the locale reference
properly ...
I simply launch a w.Miniframe now before the SplashScreen. Thus I get
back the language choice and set it before launching the SplashScreen
(which launches my main application frame)
Appreciate the help
Cheers,
T
···
Am 23.04.12 18:38, schrieb Robin Dunn:
On 4/23/12 6:35 AM, Tobias Weber wrote:
Hi,
I want to display a SingleChoiceDialog on startup of my application in
which the user sets the desired language.
All languages are in gettext format and work.
Now:
Whenever I did this via "set the language to the OS language
automatically", I usually added a defaultOS languag and get the
translation part in the head of my app like this:
locale = wx.locale(wx.LANGUAGE_DEFAULT)
lang = locale.getdefaultlocale()[0]
APPDIR = os.getcwd()
LOCALEDIR = os.path.join(APPDIR, "locale", lang)
LOCALEDOMAIN = "i18n"
wx.SetDefaultPyEncoding("iso-8859-15")
_ = wx.GetTranslation
The problem now is that it seems like, once I initialise any frame, I
cannot change the locale part anymore, i.e. via a SingleChoice dialog,
popping up like a SplashScreen...
I do not want to change the language after startup,
The structure of my app is like this:
class My App....
def OnInit(self):
splash = MySplashScreen()
splash.Show()
return True
I had planned to display the language dialog in my SplashScreen class
before I call the main application frame:
lang_choice_dlg = wx.SingleChoiceDialog (self, 'Please select your
language', 'Language choice',
language_list,
wx.CHOICEDLG_STYLE
)
if lang_choice_dlg.ShowModal() == wx.ID_OK:
lang = (lang_choice_dlg.GetStringSelection())
lang_choice_dlg.Destroy()
APPDIR = os.getcwd()
LOCALEDIR = os.path.join(APPDIR, "locale", lang)
LOCALEDOMAIN = "i18n"
wx.SetDefaultPyEncoding("iso-8859-15")
_ = wx.GetTranslation
frame = AuiFrame(None)
frame.Show( )
This does not work ... anybody with a hint what I am missing? Is the
AuiFrame maybe translated before I actually call it? What can I do do
prevent it from this?
You need to create an instance of wx.Locale with the language choice,
(and tell it where LOCALEDIR is and tell it to add your message
catalog.) Also, you need to hold a reference to the locale object,
otherwise it will restore to the previous settings when the locale
object goes out of scope. For example:
Also, if you have more than one module you will probably want to set _
in builtins too so its value of wx.GetTranslation is seen everywhere
in your application.
There are some examples in the wiki that may help for this, and also
using Python's standard gettext instead of wx's if you would rather go
that path.