void progect::createActions(){rusAction = new QAction(tr("Russian"),this);connect(rusAction,SIGNAL(triggered()),SLOT(rusLang()));}
void progect::rusLang(){ QTranslator *translator =new QTranslator(0); translator->load("/translations/paint2d_rus.qm"); qApp->installTranslator(translator);}
C++ (Qt)void Gui::changeEvent(QEvent* event){ if (event->type() == QEvent::LanguageChange) this->retranslateUi(); QWidget::changeEvent(event);} void Gui::retranslateUi(){ this->actionsLabel1.setText(QApplication::translate("Gui", "ACTION:")); //название класса, перевод //...}
this->actionsLabel1.setText(QApplication::translate("Gui", "ACTION:"));
this->actions(Label1.setText(QApplication::translate("Gui", "ACTION:")));
C++ (Qt)void Gui::changeEvent(QEvent* event){ if (event->type() == QEvent::LanguageChange) retranslate (); QWidget::changeEvent(event);} void Gui::retranslate(){ actionsLabel1.setText(tr("Action name")); actionsLabel2.setText(tr("Action 2 name")); //...}
paint2d::paint2d(){ createActions(); createMenus(); createToolBars(); setWindowIcon(QIcon(":/images/help-about-logo.png")); retranslateUi();}void paint2d::changeEvent(QEvent* event){ if (event->type() == QEvent::LanguageChange) retranslateUi (); QWidget::changeEvent(event);}void paint2d::createMenus(){ fileMenu = new QMenu(this); menuBar()->addMenu(fileMenu); fileMenu->addAction(newAction); fileMenu->addAction(openAction); fileMenu->addAction(saveAction); ...}void paint2d::createActions(){ newAction = new QAction(this); newAction->setIcon(QIcon(":/images/new.png")); newAction->setShortcut(QKeySequence::New); connect(newAction, SIGNAL(triggered()), this, SLOT(newFile())); ...}void paint2d::createToolBars(){ fileToolBar = new QToolBar; addToolBar(fileToolBar); fileToolBar->addAction(newAction); fileToolBar->addAction(openAction); ...}void paint2d::retranslateUi(){ fileMenu->setTitle(tr("File")); editMenu->setTitle(tr("Edit")); languageMenu->setTitle(tr("Language")); ...}