1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

Mapeditor will load selected translation on start

This commit is contained in:
Ivan Savenko 2022-12-26 23:29:42 +02:00
parent abc7c890bf
commit a3ee8bb47f
3 changed files with 41 additions and 1 deletions

View File

@ -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)

View File

@ -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()

View File

@ -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();