void QCoreApplication::removeTranslator ( QTranslator * translationFile ) [static]Removes the translation file translationFile from the list of translation files used by this application. (It does not delete the translation file from the file system.)See also installTranslator(), translate(), and QObject::tr().
void MainWindow::triggeredRussian(){ QTranslator* translator = new QTranslator; QCoreApplication::removeTranslator(translator); m_rus = true; qDebug() << m_rus; kn_eng->setChecked(false); translator->load("./pr1_ru.qm","."); qDebug() << translator->load("./pr1_ru.qm","."); qApp->installTranslator(translator); }void MainWindow::triggeredEnglish(){//removeTranslator(translator);// QCoreApplication::removeTranslator(translator);// QTranslator* translator = new QTranslator; m_rus = false; kn_rus->setChecked(false);// translator->load("./pr1_en.qm",".");// qDebug() << translator->load("./pr1_en.qm",".");// qApp->installTranslator(translator);}bool MainWindow::event(QEvent* e){ if (e->type() == QEvent::LanguageChange) { retranslateUi(this); return true; } return QMainWindow::event(e);}
qApp->installTranslator(translator);
void MainWindow::triggeredRussian(){ QCoreApplication::removeTranslator(translator); m_rus = true; qDebug() << m_rus; kn_eng->setChecked(false); translator->load("./pr1_ru.qm","."); qDebug() << translator->load("./pr1_ru.qm","."); qApp->installTranslator(translator); }void MainWindow::triggeredEnglish(){ QCoreApplication::removeTranslator(&translator); m_rus = false; kn_rus->setChecked(false); translator->load("./pr1_en.qm","."); qDebug() << translator->load("./pr1_en.qm","."); qApp->installTranslator(translator);}bool MainWindow::event(QEvent* e){ if (e->type() == QEvent::LanguageChange) { retranslateUi(this); return true; } return QMainWindow::event(e);}
C++ (Qt)class MainWindow{... QTranslator * translator;...} MainWindow::MainWindow(){... translator = new QTranslator( this );...}
QTextCodec::setCodecForTr(QTextCodec::codecForName("Windows-1251"));textEdit->setText(tr("The entered number of seconds ")+QString::number(iS) + tr(" corresponds ") + QString::number(oH) + tr(" hours, " ) + QString::number(oM) + tr(" minutes, ") + QString::number(oS) + tr(" seconds"));
MainWindow::MainWindow(){... translator = new QTranslator( this );...}
C++ (Qt)textEdit->setText(tr("The entered number of seconds %1 corresponds %2 hours, %3 minutes, %4 seconds").arg(iS).arg(oH).arg(oM).arg(oS));
C++ (Qt)void MainWindow::retranslateTextEdit(){ textEdit->setText( tr("The entered number of seconds %1 corresponds %2 hours, %3 minutes, %4 seconds") .arg( iS_ ) .arg( oH_ ) .arg( oM_ ) .arg( oS_ ) );
class MainWindow : public QMainWindow, Ui::MainWindow{ Q_OBJECTpublic: bool m_rus; bool event(QEvent* e); int iS, oS, oM, oH; QTranslator* translator; MainWindow(QMainWindow* p = 0) : QMainWindow(p) { translator = new QTranslator(this); m_rus = true; setupUi(this);............
.................void MainWindow::retranslateTextEdit(){ textEdit->setText( tr("The entered number of seconds %1 corresponds %2 hours, %3 minutes, %4 seconds") .arg( iS ) .arg( oH ) .arg( oM ) .arg( oS ) );}...........
if русский { пишем по-русски}if английский { пишем по-английски}
<message> <location filename="proga1.cpp" line="32"/> <source>The entered number of seconds %1 corresponds %2 hours, %3 minutes, %4 seconds</source> <translation>Введенное количество секунд %1 соответствует %2 часам, %3 минутам, %4 секундам</translation> </message>