Add internat sample command line option to skip the locale dialog
Getting this dialog all the time is annoying when testing, so add another command line option to set the locale unconditionally. This commit is best viewed ignoring whitespace-only changes.
This commit is contained in:
@@ -57,14 +57,23 @@
|
|||||||
class MyApp: public wxApp
|
class MyApp: public wxApp
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MyApp() { m_setLocale = true; }
|
MyApp() { m_setLocale = Locale_Ask; }
|
||||||
|
|
||||||
virtual void OnInitCmdLine(wxCmdLineParser& parser) wxOVERRIDE;
|
virtual void OnInitCmdLine(wxCmdLineParser& parser) wxOVERRIDE;
|
||||||
virtual bool OnCmdLineParsed(wxCmdLineParser& parser) wxOVERRIDE;
|
virtual bool OnCmdLineParsed(wxCmdLineParser& parser) wxOVERRIDE;
|
||||||
virtual bool OnInit() wxOVERRIDE;
|
virtual bool OnInit() wxOVERRIDE;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool m_setLocale; // if false, skip setting locale entirely
|
// Specifies whether we should use the current locale or not. By default we
|
||||||
|
// ask the user about it, but it's possible to override this using the
|
||||||
|
// command line options.
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
Locale_Ask,
|
||||||
|
Locale_Set,
|
||||||
|
Locale_Skip
|
||||||
|
} m_setLocale;
|
||||||
|
|
||||||
wxLocale m_locale; // locale we'll be using
|
wxLocale m_locale; // locale we'll be using
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -153,11 +162,14 @@ wxIMPLEMENT_APP(MyApp);
|
|||||||
// command line arguments handling
|
// command line arguments handling
|
||||||
|
|
||||||
static const char* OPTION_NO_LOCALE = "no-locale";
|
static const char* OPTION_NO_LOCALE = "no-locale";
|
||||||
|
static const char* OPTION_SET_LOCALE = "set-locale";
|
||||||
|
|
||||||
void MyApp::OnInitCmdLine(wxCmdLineParser& parser)
|
void MyApp::OnInitCmdLine(wxCmdLineParser& parser)
|
||||||
{
|
{
|
||||||
parser.AddSwitch("n", OPTION_NO_LOCALE,
|
parser.AddSwitch("n", OPTION_NO_LOCALE,
|
||||||
_("skip setting locale on startup"));
|
_("skip setting locale on startup"));
|
||||||
|
parser.AddSwitch("y", OPTION_SET_LOCALE,
|
||||||
|
_("do set locale on startup without asking"));
|
||||||
|
|
||||||
wxApp::OnInitCmdLine(parser);
|
wxApp::OnInitCmdLine(parser);
|
||||||
}
|
}
|
||||||
@@ -169,7 +181,18 @@ bool MyApp::OnCmdLineParsed(wxCmdLineParser& parser)
|
|||||||
|
|
||||||
if ( parser.Found(OPTION_NO_LOCALE) )
|
if ( parser.Found(OPTION_NO_LOCALE) )
|
||||||
{
|
{
|
||||||
m_setLocale = false;
|
m_setLocale = Locale_Skip;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( parser.Found(OPTION_SET_LOCALE) )
|
||||||
|
{
|
||||||
|
if ( m_setLocale == Locale_Skip )
|
||||||
|
{
|
||||||
|
wxLogWarning("--%s option overrides --%s",
|
||||||
|
OPTION_SET_LOCALE, OPTION_NO_LOCALE);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_setLocale = Locale_Set;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -190,9 +213,10 @@ bool MyApp::OnInit()
|
|||||||
const wxString
|
const wxString
|
||||||
langDesc = langInfo ? langInfo->Description
|
langDesc = langInfo ? langInfo->Description
|
||||||
: "the default system locale";
|
: "the default system locale";
|
||||||
if ( m_setLocale )
|
|
||||||
|
if ( m_setLocale == Locale_Ask )
|
||||||
{
|
{
|
||||||
if ( wxMessageBox
|
m_setLocale = wxMessageBox
|
||||||
(
|
(
|
||||||
wxString::Format
|
wxString::Format
|
||||||
(
|
(
|
||||||
@@ -201,7 +225,10 @@ bool MyApp::OnInit()
|
|||||||
),
|
),
|
||||||
"wxWidgets i18n (internat) sample",
|
"wxWidgets i18n (internat) sample",
|
||||||
wxYES_NO
|
wxYES_NO
|
||||||
) == wxYES )
|
) == wxYES ? Locale_Set : Locale_Skip;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( m_setLocale == Locale_Set )
|
||||||
{
|
{
|
||||||
// don't use wxLOCALE_LOAD_DEFAULT flag so that Init() doesn't return
|
// don't use wxLOCALE_LOAD_DEFAULT flag so that Init() doesn't return
|
||||||
// false just because it failed to load wxstd catalog
|
// false just because it failed to load wxstd catalog
|
||||||
@@ -209,19 +236,11 @@ bool MyApp::OnInit()
|
|||||||
{
|
{
|
||||||
wxLogWarning("Failed to initialize the default system locale.");
|
wxLogWarning("Failed to initialize the default system locale.");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_setLocale = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Independently of whether we succeeded to set the locale or not, try to
|
// Independently of whether we succeeded to set the locale or not, try
|
||||||
// load the translations (for the default system language) here. But don't
|
// to load the translations (for the default system language) here.
|
||||||
// do it if the user explicitly selected not to use the current locale.
|
|
||||||
if ( m_setLocale )
|
|
||||||
{
|
|
||||||
// normally this wouldn't be necessary as the catalog files would be found
|
// normally this wouldn't be necessary as the catalog files would be found
|
||||||
// in the default locations, but when the program is not installed the
|
// in the default locations, but when the program is not installed the
|
||||||
// catalogs are in the build directory where we wouldn't find them by
|
// catalogs are in the build directory where we wouldn't find them by
|
||||||
|
|||||||
Reference in New Issue
Block a user