C++ (Qt)
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
p = new QLabel(tr("Русский"));
translator = new QTranslator(this);
this->ui->gridLayout->addWidget(p,3,0);
language = RU;
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::changeEvent(QEvent * event)
{
if (event->type() == QEvent::LanguageChange) {
if (language == RU)
{
language = RU;
p->setText(tr("Русский"));
}
if (language == KZ)
{
language = KZ;
p->setText(tr("қазақ тілі"));
}
} else
QWidget::changeEvent(event);
}
void MainWindow::on_pushButton_clicked()
{
if (ui->comboBox->currentIndex() == 0)
{
language = RU;
QApplication::removeTranslator(translator);
ui->retranslateUi(this);
return;
}
if (ui->comboBox->currentIndex() == 1)
{
language = KZ;
if (!translator->load("C:\\Qt\\Qt5.0.2\\Tools\\QtCreator\\bin\\translation\\helloworld_ru"))
QMessageBox::critical(0,"", "Не загрузился Перевод");
else
{
QApplication::installTranslator(translator);
ui->retranslateUi(this);
}
return;
}
}
Вот! Я теперь оставляю жить QTranslator