int main(int argc, char *argv[]){ QApplication a(argc, argv); QTranslator Translator; QStringList LangPaths; LangPaths << QLibraryInfo::location(QLibraryInfo::TranslationsPath) << a.applicationDirPath(); for (int i = 0; i < LangPaths.count(); i++) { if (Translator.load("qt_ru", LangPaths[i])) { QCoreApplication::installTranslator(&Translator); break; } }}
QLibraryInfo::location(QLibraryInfo::TranslationsPath)
if (Translator.load("qt_ru", "c:/")) QCoreApplication::installTranslator(&Translator);
QTranslator Translator; QStringList LangPaths; if (Translator.load(":tr/qt_ru.qm")) QCoreApplication::installTranslator(&Translator);
#include <QtGui>#include <QtWidgets>int main(int argc, char *argv[]){ QApplication a(argc, argv); QTranslator Translator; QString path; path = ":/tr/qt_ru.qm"; if (Translator.load(path)) { QCoreApplication::installTranslator(&Translator); QMessageBox::information(0, "Translator", path, QMessageBox::Yes, QMessageBox::No); } path = ":tr/"; if (Translator.load("qt_ru", path)) { QCoreApplication::installTranslator(&Translator); QMessageBox::information(0, "Translator", path, QMessageBox::Yes, QMessageBox::No); } path = "c:/qt_ru"; if (Translator.load("qt_ru", path)) { QCoreApplication::installTranslator(&Translator); QMessageBox::information(0, "Translator", path, QMessageBox::Yes, QMessageBox::No); } path = "c:/qt_ru.qm"; if (Translator.load(path)) { QCoreApplication::installTranslator(&Translator); QMessageBox::information(0, "Translator", path, QMessageBox::Yes, QMessageBox::No); }}
path = QLibraryInfo::location(QLibraryInfo::TranslationsPath); QMessageBox::information(0, "Path", path, QMessageBox::Apply); if (Translator.load("qt_ru", path)) { QCoreApplication::installTranslator(&Translator); QMessageBox::information(0, "Translator", path, QMessageBox::Yes, QMessageBox::No); }