Dienstag, 26. Februar 2013

mehrsprachige QT-Programme mit kDevelop erstellen




main.cpp

#include
#include "helloworld.h"
#include
#include


int main(int argc, char** argv)
{
    QApplication app(argc, argv);

    QString locale = QLocale::system().name();
    QTranslator translator;
    translator.load(QString("helloworld_") +locale);
    app.installTranslator(&translator);
    helloworld foo;
    foo.show();
    return app.exec();
}


helloworld.cpp

#include "helloworld.h"

#include
#include
#include
#include


helloworld::helloworld()
{

    QLabel* l = new QLabel( this );
    l->setText(tr( "Hello World!" ));
    setCentralWidget( l );
    QAction* a = new QAction(this);
    a->setText(tr( "&Quit" ));
    connect(a, SIGNAL(triggered()), SLOT(close()) );
    menuBar()->addMenu(tr( "&File" ))->addAction( a );
}

helloworld::~helloworld()
{}

#include "helloworld.moc"


helloworld.h

#ifndef helloworld_H
#define helloworld_H

#include

class helloworld : public QMainWindow
{
Q_OBJECT
public:
    helloworld();
    virtual ~helloworld();
};

#endif // helloworld_H



helloworld.pro

SOURCES      = main.cpp helloworld.cpp
TRANSLATIONS = helloworld_de.ts



developer@localhost:~/projects/helloworld> lupdate helloworld.pro


linguist öffnen und die Datei: helloworld_de.ts laden

dann die Übersetzung machen.

Datei -> Freigeben

Die datei: helloworld_de.qm nach build im Projektverzeichnis kopieren.

Dann sollte das Helloworld in deutsch starten
wenn die Variable LANG auf de_DE.UTF-8 steht






Keine Kommentare:

Kommentar veröffentlichen