I am trying to make a program with text translated to the users language. To get going I figured I should start with a simple hello world program and I got that working in the console, using gettext.
I don't want to make a console program, so I would like to port this idea to a wxWidgets gui. I created the code below and tried to extract the .pot file with the original strings to start translating. As you can see I tried this in several ways, making the code more and more messy, but I have not yet found the correct way.
Is there anybody that can tell me what to change so that I can extract the strings from this code to a .pot file for translation?
Thanks in advance for any help.
Kind regards, Nico
mainApp.h, just to start things
Code: Select all
#ifndef MAINAPP_H
#define MAINAPP_H
#include <wx/intl.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include "window.h"
#include <wx/image.h>
#include <wx/app.h>
class mainApp : public wxApp
{
public:
virtual bool OnInit();
protected:
private:
};
#endif // MAINAPP_H
Code: Select all
#include "mainApp.h"
IMPLEMENT_APP(mainApp);
bool mainApp::OnInit()
{
bool wxsOK = true;
wxInitAllImageHandlers();
if ( wxsOK )
{
window Dlg(0);
SetTopWindow(&Dlg);
Dlg.ShowModal();
wxsOK = false;
}
return wxsOK;
}
Code: Select all
#ifndef WINDOW_H
#define WINDOW_H
#define _(String) gettext(String)
// #define N_(String) String
// #define textdomain(Domain)
// #define bindtextdomain(Package, Directory)
//(*Headers(window)
#include <wx/stattext.h>
#include <wx/dialog.h>
#include "C:\Program Files\GnuWin32\include\libintl.h"
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
//*)
class window: public wxDialog
{
public:
window(wxWindow* parent,wxWindowID id=wxID_ANY,const wxPoint& pos=wxDefaultPosition,const wxSize& size=wxDefaultSize);
virtual ~window();
//(*Declarations(window)
wxStaticText* StaticText1;
//*)
protected:
//(*Identifiers(window)
static const long ID_STATICTEXT1;
//*)
private:
//(*Handlers(window)
//*)
DECLARE_EVENT_TABLE()
};
#endif
Code: Select all
#include "window.h"
//(*InternalHeaders(window)
#include <wx/intl.h>
//#include <wx/string.h>
//*)
#include "C:\Program Files\GnuWin32\include\libintl.h"
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
//(*IdInit(window)
const long window::ID_STATICTEXT1 = wxNewId();
//*)
BEGIN_EVENT_TABLE(window,wxDialog)
//(*EventTable(window)
//*)
END_EVENT_TABLE()
window::window(wxWindow* parent,wxWindowID id,const wxPoint& pos,const wxSize& size)
{
setlocale( LC_ALL, "" );
bindtextdomain( "test", "./vertaal/" );
textdomain( "test" );
//(*Initialize(window)
Create(parent, id, _("Test window"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, _T("id"));
SetClientSize(wxDefaultSize);
Move(wxDefaultPosition);
StaticText1 = new wxStaticText(this, ID_STATICTEXT1, _("Dit is een test om te zien of we dit in runtime kunnen vertalen."), wxPoint(56,152), wxDefaultSize, 0, _T("ID_STATICTEXT1"));
//*)
}
window::~window()
{
//(*Destroy(window)
//*)
}
p.s. Just in case the code is right but my use of it is wrong, to extract te information I use the following command in command prompt:
C:\Program Files\GnuWin32\bin>xgettext -d test -s -o "c:\Documents and Settings\Nico\cpp workspace\TestVertalen\vertaal\test.pot" "c:\Documents and Settings\Nico\cpp workspace\TestVertalen\window.cpp"