[wxWidgets]Internationalosierung nur in einem Frame



  • Hallo!
    Ich habe ein Problem.
    Ich bin gerade dabei meine Anwendung zu internationalisieren.
    Jedoch wird nur 'latein_suiteFrame' internationalisiert.
    'SettingsDialog' bleibt in Englisch.
    Woran könnte das liegen?

    Sourcecode:

    latein_suiteGUI.h

    ///////////////////////////////////////////////////////////////////////////
    // C++ code generated with wxFormBuilder (version Feb 17 2010)
    // http://www.wxformbuilder.org/
    //
    // PLEASE DO "NOT" EDIT THIS FILE!
    ///////////////////////////////////////////////////////////////////////////
    
    #ifndef __latein_suiteGUI__
    #define __latein_suiteGUI__
    
    #include <wx/intl.h>
    
    #include <wx/statusbr.h>
    #include <wx/gdicmn.h>
    #include <wx/font.h>
    #include <wx/colour.h>
    #include <wx/settings.h>
    #include <wx/string.h>
    #include <wx/bitmap.h>
    #include <wx/image.h>
    #include <wx/icon.h>
    #include <wx/menu.h>
    #include <wx/textctrl.h>
    #include <wx/sizer.h>
    #include <wx/panel.h>
    #include <wx/notebook.h>
    #include <wx/frame.h>
    #include <wx/stattext.h>
    #include <wx/choice.h>
    #include <wx/dialog.h>
    
    ///////////////////////////////////////////////////////////////////////////
    
    ///////////////////////////////////////////////////////////////////////////////
    /// Class latein_suiteFrame
    ///////////////////////////////////////////////////////////////////////////////
    class latein_suiteFrame : public wxFrame
    {
    	private:
    
    	protected:
    		wxStatusBar* statusbarMain;
    		wxMenuBar* menubarMain;
    		wxMenu* menuFile;
    		wxMenu* menuEdit;
    		wxMenu* menuHelp;
    		wxNotebook* notebook1;
    		wxPanel* panelTranslate;
    		wxTextCtrl* textCtrlInput;
    		wxTextCtrl* textCtrlTranslation;
    
    		// Virtual event handlers, overide them in your derived class
    		virtual void OnOpenSettingsFrame( wxCommandEvent& event ) { event.Skip(); }
    		virtual void OnQuit( wxCommandEvent& event ) { event.Skip(); }
    
    	public:
    
    		latein_suiteFrame( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Latein Suite"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 800,900 ), long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL );
    		~latein_suiteFrame();
    };
    
    ///////////////////////////////////////////////////////////////////////////////
    /// Class SettingsDialog
    ///////////////////////////////////////////////////////////////////////////////
    class SettingsDialog : public wxDialog
    {
    	private:
    
    	protected:
    		wxStaticText* staticLanguage;
    		wxChoice* choiceLanguage;
    
    		// Virtual event handlers, overide them in your derived class
    		virtual void OnInitSettingsDlg( wxInitDialogEvent& event ) { event.Skip(); }
    
    	public:
    
    		SettingsDialog( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Settings"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 500,500 ), long style = wxDEFAULT_DIALOG_STYLE );
    		~SettingsDialog();
    
    };
    
    #endif //__latein_suiteGUI__
    

    latein_suiteGUI.cpp

    ///////////////////////////////////////////////////////////////////////////
    // C++ code generated with wxFormBuilder (version Feb 17 2010)
    // http://www.wxformbuilder.org/
    //
    // PLEASE DO "NOT" EDIT THIS FILE!
    ///////////////////////////////////////////////////////////////////////////
    
    #include <wx/wxprec.h>
    
    #include "latein_suiteGUI.h"
    
    ///////////////////////////////////////////////////////////////////////////
    
    latein_suiteFrame::latein_suiteFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style )
    {
    	this->SetSizeHints( wxDefaultSize, wxDefaultSize );
    
    	statusbarMain = this->CreateStatusBar( 1, wxST_SIZEGRIP, wxID_ANY );
    	menubarMain = new wxMenuBar( 0 );
    	menuFile = new wxMenu();
    	wxMenuItem* menitemSettings;
    	menitemSettings = new wxMenuItem( menuFile, wxID_ANY, wxString( _("Settings") ) , _("Opens the settings dialog"), wxITEM_NORMAL );
    	menuFile->Append( menitemSettings );
    
    	wxMenuItem* meniFileseperator1;
    	meniFileseperator1 = menuFile->AppendSeparator();
    
    	wxMenuItem* menuitemQuit;
    	menuitemQuit = new wxMenuItem( menuFile, wxID_ANY, wxString( _("Quit") ) , wxEmptyString, wxITEM_NORMAL );
    	menuFile->Append( menuitemQuit );
    
    	menubarMain->Append( menuFile, _("File") ); 
    
    	menuEdit = new wxMenu();
    	wxMenuItem* menuitemCut;
    	menuitemCut = new wxMenuItem( menuEdit, wxID_ANY, wxString( _("Cut") ) , wxEmptyString, wxITEM_NORMAL );
    	menuEdit->Append( menuitemCut );
    	menuitemCut->Enable( false );
    
    	wxMenuItem* menuitemCopy;
    	menuitemCopy = new wxMenuItem( menuEdit, wxID_ANY, wxString( _("Copy") ) , wxEmptyString, wxITEM_NORMAL );
    	menuEdit->Append( menuitemCopy );
    	menuitemCopy->Enable( false );
    
    	wxMenuItem* menuitemPaste;
    	menuitemPaste = new wxMenuItem( menuEdit, wxID_ANY, wxString( _("Paste") ) , wxEmptyString, wxITEM_NORMAL );
    	menuEdit->Append( menuitemPaste );
    	menuitemPaste->Enable( false );
    
    	wxMenuItem* menuitemDelete;
    	menuitemDelete = new wxMenuItem( menuEdit, wxID_ANY, wxString( _("Delete") ) , wxEmptyString, wxITEM_NORMAL );
    	menuEdit->Append( menuitemDelete );
    	menuitemDelete->Enable( false );
    
    	menubarMain->Append( menuEdit, _("Edit") ); 
    
    	menuHelp = new wxMenu();
    	menubarMain->Append( menuHelp, _("Help") ); 
    
    	this->SetMenuBar( menubarMain );
    
    	wxBoxSizer* boxSizer1;
    	boxSizer1 = new wxBoxSizer( wxVERTICAL );
    
    	notebook1 = new wxNotebook( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
    	panelTranslate = new wxPanel( notebook1, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
    	wxFlexGridSizer* flexgridSizer1;
    	flexgridSizer1 = new wxFlexGridSizer( 2, 2, 0, 0 );
    	flexgridSizer1->SetFlexibleDirection( wxBOTH );
    	flexgridSizer1->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
    
    	textCtrlInput = new wxTextCtrl( panelTranslate, wxID_ANY, _("Insert text here..."), wxDefaultPosition, wxSize( 378,482 ), wxTE_MULTILINE|wxTE_RICH );
    	flexgridSizer1->Add( textCtrlInput, 0, wxALL, 5 );
    
    	textCtrlTranslation = new wxTextCtrl( panelTranslate, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( 378,482 ), wxTE_MULTILINE|wxTE_RICH );
    	flexgridSizer1->Add( textCtrlTranslation, 0, wxALL, 5 );
    
    	panelTranslate->SetSizer( flexgridSizer1 );
    	panelTranslate->Layout();
    	flexgridSizer1->Fit( panelTranslate );
    	notebook1->AddPage( panelTranslate, _("Translate"), true );
    
    	boxSizer1->Add( notebook1, 1, wxEXPAND, 5 );
    
    	this->SetSizer( boxSizer1 );
    	this->Layout();
    
    	this->Centre( wxBOTH );
    
    	// Connect Events
    	this->Connect( menitemSettings->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( latein_suiteFrame::OnOpenSettingsFrame ) );
    	this->Connect( menuitemQuit->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( latein_suiteFrame::OnQuit ) );
    }
    
    latein_suiteFrame::~latein_suiteFrame()
    {
    	// Disconnect Events
    	this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( latein_suiteFrame::OnOpenSettingsFrame ) );
    	this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( latein_suiteFrame::OnQuit ) );
    
    }
    
    SettingsDialog::SettingsDialog( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style )
    {
    	this->SetSizeHints( wxDefaultSize, wxDefaultSize );
    
    	wxFlexGridSizer* flexgridSizer1;
    	flexgridSizer1 = new wxFlexGridSizer( 2, 2, 0, 200 );
    	flexgridSizer1->SetFlexibleDirection( wxBOTH );
    	flexgridSizer1->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
    
    	staticLanguage = new wxStaticText( this, wxID_ANY, _("Choose your Language:"), wxDefaultPosition, wxSize( -1,-1 ), 0 );
    	staticLanguage->Wrap( -1 );
    	flexgridSizer1->Add( staticLanguage, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
    
    	wxString choiceLanguageChoices[] = { _("English"), _("German") };
    	int choiceLanguageNChoices = sizeof( choiceLanguageChoices ) / sizeof( wxString );
    	choiceLanguage = new wxChoice( this, wxID_ANY, wxPoint( -1,-1 ), wxSize( 128,-1 ), choiceLanguageNChoices, choiceLanguageChoices, 0 );
    	choiceLanguage->SetSelection( 0 );
    	flexgridSizer1->Add( choiceLanguage, 0, wxALL|wxEXPAND, 5 );
    
    	this->SetSizer( flexgridSizer1 );
    	this->Layout();
    
    	this->Centre( wxBOTH );
    
    	// Connect Events
    	this->Connect( wxEVT_INIT_DIALOG, wxInitDialogEventHandler( SettingsDialog::OnInitSettingsDlg ) );
    }
    
    SettingsDialog::~SettingsDialog()
    {
    	// Disconnect Events
    	this->Disconnect( wxEVT_INIT_DIALOG, wxInitDialogEventHandler( SettingsDialog::OnInitSettingsDlg ) );
    
    }
    

    latein_suiteApp.h

    #ifndef LATEIN_SUITEAPP_H_INCLUDED
    #define LATEIN_SUITEAPP_H_INCLUDED
    
    #include <wx/wx.h>
    
    class latein_suiteApp : public wxApp
    {
        public:
        latein_suiteApp();
        virtual ~latein_suiteApp();
        virtual bool OnInit();
        void SelectLanguage(int lang);
    
        private:
        wxLocale m_locale;
    };
    
    DECLARE_APP(latein_suiteApp)
    
    #endif // LATEIN_SUITEAPP_H_INCLUDED
    

    latein_suiteApp.cpp

    #include "latein_suiteApp.h"
    #include "latein_suiteFunc.h"
    
    #include <wx/msgdlg.h>
    #include <wx/stdpaths.h>
    
    IMPLEMENT_APP(latein_suiteApp)
    
    latein_suiteApp::latein_suiteApp()
    {
    
    }
    
    latein_suiteApp::~latein_suiteApp()
    {
    
    }
    bool latein_suiteApp::OnInit()
    {
        SelectLanguage(wxLANGUAGE_GERMAN);
        latein_suite* Frame = new latein_suite(0);
        Frame->Show();
        SetTopWindow(Frame);
        return true;
    }
    
    void latein_suiteApp::SelectLanguage(int lang)
    {
        wxString AppPath = wxStandardPathsBase::Get().GetExecutablePath();
        AppPath.Remove(AppPath.Find(wxT("latein_suite.exe")));
        //wxMessageBox(AppPath);
        wxString test;
        test << lang;
        wxMessageBox(test);
        //delete m_locale;
        m_locale.Init(lang, wxLOCALE_CONV_ENCODING);
        m_locale.AddCatalogLookupPathPrefix(AppPath);
        m_locale.AddCatalog(wxT("lang\\de_de\\de"));
        m_locale.AddCatalog(wxT("lang\\de_de\\de_de"));
    }
    

    latein_suiteFunc.h

    #ifndef __latein_suiteFunc__
    #define __latein_suiteFunc__
    
    #include "latein_suiteGUI.h"
    
    class latein_suite : public latein_suiteFrame
    {
    	public:
    		latein_suite( wxWindow* parent );
    
        protected:
            void OnQuit(wxCommandEvent& event);
            void OnOpenSettingsFrame (wxCommandEvent& event);
    };
    
    #endif
    

    latein_suiteFunc.cpp

    #include <wx/wxprec.h>
    
    #include "latein_suiteFunc.h"
    #include "latein_suiteApp.h"
    #include "latein_suiteGUI.h"
    #include "SettingsDialogFunc.h"
    
    #include <wx/msgdlg.h>
    #include <wx/app.h>
    #include <wx/filefn.h>
    #include <wx/stdpaths.h>
    
    latein_suite::latein_suite( wxWindow* parent )
    :
    latein_suiteFrame( parent )
    {
    
    }
    
    void latein_suite::OnQuit(wxCommandEvent& event)
    {
        this->Close();
    }
    
    void latein_suite::OnOpenSettingsFrame(wxCommandEvent& event)
    {
        SettingsDialog *dlg = new SettingsDialog(this);
        dlg->ShowModal();
    }
    

    SettingsDialogFunc.h

    #ifndef __SettingsDialogFunc__
    #define __SettingsDialogFunc__
    
    #include "latein_suiteGUI.h"
    
    class SettingsDialogFunc : public SettingsDialog
    {
    	protected:
    		void OnInitSettingsDlg(wxInitDialogEvent& event);
    	public:
    		SettingsDialogFunc(wxWindow* parent);
    
    };
    
    #endif
    

    SettingsDialogFunc.cpp

    #include "SettingsDialogFunc.h"
    #include <wx/msgdlg.h>
    #include <wx/stdpaths.h>
    
    SettingsDialogFunc::SettingsDialogFunc( wxWindow* parent )
    :
    SettingsDialog( parent )
    {
    
    }
    
    void SettingsDialogFunc::OnInitSettingsDlg( wxInitDialogEvent& event )
    {
    
    }
    

    Wie gesagt: Der Frame, der in 'OnOpenSettingsFrame' geöffnet wird, wird nicht übersetzt.
    Woran kann das liegen?
    wäre nett wenn ihr mir helft.



  • void  Application::ChangeLanguage(bool force)
    {
    	// Get Config
    	wxConfig * config = new wxConfig();
    	m_lang = static_cast<wxLanguage>(config->ReadLong("Language", wxLANGUAGE_UNKNOWN));
    
    	// This is for calling it from inside the program. So we can get rid of the "wrong" language.
    	if (force){
    		m_lang = wxLANGUAGE_UNKNOWN;
    	}
    
    	// Get desired Language from user based on available Languages
    	if ( m_lang == wxLANGUAGE_UNKNOWN )
    	{
    		int choice = wxGetSingleChoiceIndex(wxT("Please select Language"), 
    					 wxT("Choose Translation"), 
    					 WXSIZEOF(LangNames),
    					 LangNames);
    		m_lang = (choice == -1 ? wxLANGUAGE_DEFAULT : LangID[choice]);
    	}
    	// Init
    	if ( !m_loc.Init(m_lang, wxLOCALE_CONV_ENCODING) )
    	{
    		wxLogWarning(_("This language is not supported by the system."));
    	}
    
    	// Install Catalogue
    	const wxLanguageInfo* pInfo = wxLocale::GetLanguageInfo(m_lang);
    	if (!m_loc.AddCatalog("internat"))
    	{
    		wxLogError(wxT("Couldn't find/load the 'internat' catalog for locale '%s'."),
    			pInfo ? pInfo->GetLocaleName() : _("unknown"));
    	}
    	m_loc.AddCatalog("wxstd.mo");
    
    	// Modify Config
    	config->Write("Language", static_cast<long>(m_lang));
    	delete config;
    }
    

    So hab ich das gelöst.

    m_locale.Init(lang, wxLOCALE_CONV_ENCODING);
    m_locale.AddCatalogLookupPathPrefix(AppPath);
    m_locale.AddCatalog(wxT("lang\\de_de\\de"));
    m_locale.AddCatalog(wxT("lang\\de_de\\de_de"));
    

    Die Frage ist:
    Warum den AppPath zum Lookup hinzufügen? Der wird automatisch durchsucht. Und was ist de und de_de?
    Dann:
    Ich hab einen Katalog für meine Anwendung, der von mir stammt:
    internat.mo
    Der sitzt im verzeichnis "de" im AppPath. Hast Du also das Verzeichnis Lang, muss du AppPath + "/lang/" zum Lookup hinzufügen und den Namen des Kataloges über AddCatalogue angeben. Das Verzeichnis "de" wird automatisch gewählt.
    Siehe auch das Sample dazu.
    Hoffe das war verständlich :D.

    EDIT:
    Achja, hast Du gettext auch über die Dateien vom Formbuilder drüberlaufen lassen? Falls Du es nicht kennst, poEdit ist hervorragend zum übersetzen, ist auch mit wxWidgets gemacht.
    rya.


Log in to reply