diff --git a/mapeditor/CMakeLists.txt b/mapeditor/CMakeLists.txt index 241c6a9fa..ff9fdcd28 100644 --- a/mapeditor/CMakeLists.txt +++ b/mapeditor/CMakeLists.txt @@ -70,6 +70,13 @@ set(editor_FORMS inspector/questwidget.ui ) +set(editor_TS + translation/english.ts + translation/german.ts + translation/polish.ts + translation/russian.ts + translation/ukrainian.ts) + assign_source_group(${editor_SRCS} ${editor_HEADERS} mapeditor.rc) # Tell CMake to run moc when necessary: @@ -85,15 +92,22 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) if(TARGET Qt6::Core) qt_wrap_ui(editor_UI_HEADERS ${editor_FORMS}) + if (ENABLE_TRANSLATIONS) + qt_add_translation( editor_QM ${editor_TS} ) + endif() else() qt5_wrap_ui(editor_UI_HEADERS ${editor_FORMS}) + if (ENABLE_TRANSLATIONS) + set_source_files_properties(${editor_TS} PROPERTIES OUTPUT_LOCATION ${CMAKE_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/mapeditor/translations) + qt5_add_translation( editor_QM ${editor_TS} ) + endif() endif() if(WIN32) set(editor_ICON mapeditor.rc) endif() -add_executable(vcmieditor WIN32 ${editor_SRCS} ${editor_HEADERS} ${editor_UI_HEADERS} ${editor_ICON}) +add_executable(vcmieditor WIN32 ${editor_QM} ${editor_SRCS} ${editor_HEADERS} ${editor_UI_HEADERS} ${editor_ICON}) if(WIN32) set_target_properties(vcmieditor @@ -132,6 +146,7 @@ add_custom_command(TARGET vcmieditor POST_BUILD install(TARGETS vcmieditor DESTINATION ${BIN_DIR}) # copy whole directory install(DIRECTORY icons DESTINATION ${DATA_DIR}/mapeditor) +install(DIRECTORY translation DESTINATION ${DATA_DIR}/mapeditor) # Install icons and desktop file on Linux if(NOT WIN32 AND NOT APPLE) install(FILES "vcmieditor.desktop" DESTINATION share/applications) diff --git a/mapeditor/mainwindow.cpp b/mapeditor/mainwindow.cpp index c119bee1f..ddffe4bf4 100644 --- a/mapeditor/mainwindow.cpp +++ b/mapeditor/mainwindow.cpp @@ -115,6 +115,19 @@ void MainWindow::parseCommandLine(ExtractionOptions & extractionOptions) parser.isSet("d")}}; } +void MainWindow::loadTranslation() +{ +#ifdef ENABLE_QT_TRANSLATIONS + std::string languageCode = settings["general"]["language"].String(); + QString translationFile = "./mapeditor/translations/" + QString::fromStdString(languageCode) + ".qm"; + + if (!translator.load(translationFile)) + logGlobal->error("Failed to load translation"); + if (!qApp->installTranslator(&translator)) + logGlobal->error("Failed to install translator"); +#endif +} + MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWindow), @@ -169,6 +182,12 @@ MainWindow::MainWindow(QWidget* parent) : conf.init(); logGlobal->info("Loading settings"); + loadTranslation(); + + ui->setupUi(this); + loadUserSettings(); //For example window size + setTitle(); + init(); graphics = new Graphics(); // should be before curh->init() diff --git a/mapeditor/mainwindow.h b/mapeditor/mainwindow.h index 3464c45b2..1ee108797 100644 --- a/mapeditor/mainwindow.h +++ b/mapeditor/mainwindow.h @@ -29,6 +29,10 @@ class MainWindow : public QMainWindow const QString mainWindowSizeSetting = "MainWindow/Size"; const QString mainWindowPositionSetting = "MainWindow/Position"; +#ifdef ENABLE_QT_TRANSLATIONS + QTranslator translator; +#endif + public: explicit MainWindow(QWidget *parent = nullptr); ~MainWindow(); @@ -48,6 +52,8 @@ public: MapController controller; + void loadTranslation(); + private slots: void on_actionOpen_triggered();