ich müsste in der main-Routine etwas übersetzen (und zwar die Ausgabe, wie man die Programmparameter korrekt nutzt). Leider klappt die Übersetzung da nicht. Mein Beispielcode:
main.pro:
Code: Alles auswählen
TEMPLATE = app
QT *= gui
CONFIG *= qt console warn_on release
TARGET = main
HEADERS = dialog.h
SOURCES = main.cpp
TRANSLATIONS = main.tsCode: Alles auswählen
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
#include <QLabel>
#include <QVBoxLayout>
class Dialog : public QDialog
{
Q_OBJECT
public:
Dialog( QWidget *parent = 0 )
: QDialog(parent)
{
QVBoxLayout *layout = new QVBoxLayout;
QLabel *label = new QLabel( tr("English3") );
layout->addWidget(label);
label = new QLabel( "English2" );
layout->addWidget(label);
setLayout(layout);
setWindowTitle( tr("English1") );
}
};
#endif
Code: Alles auswählen
#include <QString>
#include <QCoreApplication>
#include <QApplication>
#include <QTranslator>
#include <QLocale>
#include <QMessageBox>
#include <iostream>
#include "dialog.h"
int main( int argc, char *argv[] )
{
QApplication app( argc, argv );
QTranslator appTranslator;
appTranslator.load( "main" );
app.installTranslator( &appTranslator );
std::cout << app.tr("English1").toStdString() << std::endl;
QMessageBox::information(0, "English2", app.tr("English3") );
Dialog dialog;
return dialog.exec();
}
Code: Alles auswählen
lupdate main.pro -ts main.ts
linguist-qt4 main.ts
lrelease main.proWenn ich das Programm starte, sind aber nur die Strings im Dialog übersetzt? Was mache ich denn falsch?
Wenn das da oben funktioniert, brauche ich das Ganze dann für eine Konsolenanwendung, sprich ohne "gui" in der QT-Variable und maximal mit QCoreApplication.
Gruß Dee
PS: System ist Ubuntu 9.10, Qt 4.5.2.