Multilingual application
- Nucleorion
- Knows some wx things
- Posts: 45
- Joined: Sat Jan 07, 2017 10:08 pm
Re: Multilingual application
Whell. And now, how is the best way to I save the lang selected?
I try whit config.ini but this is loaded after app.cpp
I try whit config.ini but this is loaded after app.cpp
Re: Multilingual application
config.ini should work, you just have to load it before you create any GUI elements, i.e. at the beginning of wxApp::OnInit()
Use the source, Luke!
- Nucleorion
- Knows some wx things
- Posts: 45
- Joined: Sat Jan 07, 2017 10:08 pm
Re: Multilingual application
I've already tried that, but then it will not let me use it in main.cpp
I tried to put it in duplicate ie declare it and load it both in the app and in the mail. And works. But I do not think that's the right way to do it.
I tried to put it in duplicate ie declare it and load it both in the app and in the mail. And works. But I do not think that's the right way to do it.
Re: Multilingual application
Please explain. What's "it" in this sentence? Maybe show some code.I've already tried that, but then it will not let me use it in main.cpp
Use the source, Luke!
- Nucleorion
- Knows some wx things
- Posts: 45
- Joined: Sat Jan 07, 2017 10:08 pm
Re: Multilingual application
ExampleApp.h
ExampleApp.cpp
ExampleMain.cpp
Error: 'ConfigINI' was not declared in this scope|
Code: Select all
class MultilingualExampleApp : public wxApp
{
public:
virtual bool OnInit();
wxLocale m_locale;
wxFileConfig *ConfigINI = new wxFileConfig(wxEmptyString,
wxEmptyString,
wxPathOnly(wxStandardPaths::Get().GetDataDir()) + _T("\\config.ini"));
};
Code: Select all
bool MultilingualExampleApp::OnInit()
{
wxFileName f(wxStandardPaths::Get().GetExecutablePath());
wxString appPath(f.GetPath()+ _T("\\config.ini"));
ConfigINI->SetPath(appPath);
ConfigINI->SetPath("/settings");
wxString langSelected=ConfigINI->Read("Language","en_US");///Read("Nombre","Valor por defecto")
m_locale.Init(wxLANGUAGE_SPANISH);//Init to the spanish
wxLocale::AddCatalogLookupPathPrefix(wxT(".\\langs"));//add path
m_locale.AddCatalog( wxT ("es"));//add catalog wxWidgetspath/locale/es.mo
m_locale.AddCatalog(langSelected);//add my .mo edit files
Code: Select all
void MultilingualExampleFrame::OnMenu_Language_English_Selected(wxCommandEvent& event)
{
ConfigINI->SetPath("/settings"); //Error in this line
ConfigINI->Write("Language","en_US");
ConfigINI->Flush();//Force save data in .ini file
}
Re: Multilingual application
Hi,
You main frame does not know about this. Just because it's public in the wxApp class doesn't mean it is accessible everywhere.
Create a function in wxApp-derived class that return this pointer and call it in the main frame class.
Thank you.
You main frame does not know about this. Just because it's public in the wxApp class doesn't mean it is accessible everywhere.
Create a function in wxApp-derived class that return this pointer and call it in the main frame class.
Thank you.
Re: Multilingual application
First of all, you should move the initialization of ConfigINI to the OnInit method.
Second: ConfigINI is defined in wxApp, so you can't access it directly from MultilingualExampleFrame.
Do it this way:
Second: ConfigINI is defined in wxApp, so you can't access it directly from MultilingualExampleFrame.
Do it this way:
Code: Select all
ConfigINI = new wxFileConfig(wxEmptyString,
wxEmptyString,
wxPathOnly(wxStandardPaths::Get().GetDataDir()) + _T("\\config.ini"));
// set global config instance
wxConfigBase::Set( ConfigINI );
Code: Select all
void MultilingualExampleFrame::OnMenu_Language_English_Selected(wxCommandEvent& event)
{
// get global config instance
wxConfigBase *config = wxConfigBase::Get();
if( config != NULL )
{
config->SetPath("/settings");
config->Write("Language","en_US");
config->Flush();//Force save data in .ini file
}
}
Use the source, Luke!
- Nucleorion
- Knows some wx things
- Posts: 45
- Joined: Sat Jan 07, 2017 10:08 pm
Re: Multilingual application
I understand this:
ExampleApp.h
ExampleApp.cpp
ExampleMain.cpp
error: cannot call member function 'virtual void wxRegConfig::SetPath(const wxString&)' without object
I think i dont understand where put lines
ExampleApp.h
Code: Select all
class MultilingualExampleApp : public wxApp
{
public:
virtual bool OnInit();
wxLocale m_locale;
wxFileConfig *ConfigINI;
};
Code: Select all
bool MultilingualExampleApp::OnInit()
{
ConfigINI = new wxFileConfig(wxEmptyString,
wxEmptyString,
wxPathOnly(wxStandardPaths::Get().GetDataDir()) + _T("\\config.ini"));
// set global config instance
wxConfig::SetPath( ConfigINI ); ///Error in this line
wxFileName f(wxStandardPaths::Get().GetExecutablePath());
wxString appPath(f.GetPath()+ _T("\\config.ini"));
ConfigINI->SetPath(appPath);
ConfigINI->SetPath("/settings");
wxString langSelected=ConfigINI->Read("Language","en_US");///Read("Nombre","Valor por defecto")
m_locale.Init(wxLANGUAGE_SPANISH);//Init to the spanish
wxLocale::AddCatalogLookupPathPrefix(wxT(".\\langs"));//add path
m_locale.AddCatalog( wxT ("es"));//add catalog wxWidgetspath/locale/es.mo
m_locale.AddCatalog(langSelected);//add my .mo edit files
Code: Select all
void MultilingualExampleFrame::OnMenu_Language_English_Selected(wxCommandEvent& event)
{
// get global config instance
wxConfigBase *config = wxConfigBase::Get();
if( config != NULL )
{
config->SetPath("/settings");
config->Write("Language","en_US");
config->Flush();//Force save data in .ini file
}
}
I think i dont understand where put lines
- Nucleorion
- Knows some wx things
- Posts: 45
- Joined: Sat Jan 07, 2017 10:08 pm
Re: Multilingual application
How I create a function in wxApp-derived class. Sorry, I need so know where is itONEEYEMAN wrote:Hi,
You main frame does not know about this. Just because it's public in the wxApp class doesn't mean it is accessible everywhere.
Create a function in wxApp-derived class that return this pointer and call it in the main frame class.
Thank you.
Re: Multilingual application
Code: Select all
wxConfig::SetPath( ConfigINI ); ///Error in this line
Code: Select all
wxConfigBase::Set( ConfigINI );
Use the source, Luke!
- Nucleorion
- Knows some wx things
- Posts: 45
- Joined: Sat Jan 07, 2017 10:08 pm
Re: Multilingual application
Code: Select all
wxConfigBase *config = wxConfigBase::Get();
'wxConfigBase' was not declared in this scope
'config' was not declared in this scope
'wxConfigBase' is not a class, namespace, or enumeration
Re: Multilingual application
You need to include "wx/config.h" so that the compiler knows what wxConfigBase is.
Use the source, Luke!
- Nucleorion
- Knows some wx things
- Posts: 45
- Joined: Sat Jan 07, 2017 10:08 pm
Re: Multilingual application
Ok. Work fine now.
I had #include <wx/config.h> in ExampleMain.h
Believe that the main.h. are picked the Main.cpp by putting the line #include "ExampleMain.h"
I had #include <wx/config.h> in ExampleMain.h
Believe that the main.h. are picked the Main.cpp by putting the line #include "ExampleMain.h"