Browse Source

Fix loading of translations

Ivan Savenko 2 years ago
parent
commit
ad7944bb83
2 changed files with 19 additions and 7 deletions
  1. 1 1
      mapeditor/CMakeLists.txt
  2. 18 6
      mapeditor/mainwindow.cpp

+ 1 - 1
mapeditor/CMakeLists.txt

@@ -98,7 +98,7 @@ if(TARGET Qt6::Core)
 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)
+		set_source_files_properties(${editor_TS} PROPERTIES OUTPUT_LOCATION ${CMAKE_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/mapeditor/translation)
 		qt5_add_translation( editor_QM ${editor_TS} )
 	endif()
 endif()

+ 18 - 6
mapeditor/mainwindow.cpp

@@ -118,13 +118,25 @@ void MainWindow::parseCommandLine(ExtractionOptions & extractionOptions)
 void MainWindow::loadTranslation()
 {
 #ifdef ENABLE_QT_TRANSLATIONS
-	std::string languageCode = settings["general"]["language"].String();
-	QString translationFile = "./mapeditor/translations/" + QString::fromStdString(languageCode) + ".qm";
+	std::string translationFile = settings["general"]["language"].String()+ ".qm";
 
-	if (!translator.load(translationFile))
-		logGlobal->error("Failed to load translation");
-	if (!qApp->installTranslator(&translator))
-		logGlobal->error("Failed to install translator");
+	QVector<QString> searchPaths;
+
+	for(auto const & string : VCMIDirs::get().dataPaths())
+		searchPaths.push_back(pathToQString(string / "mapeditor" / "translation" / translationFile));
+	searchPaths.push_back(pathToQString(VCMIDirs::get().userDataPath() / "mapeditor" / "translation" / translationFile));
+
+	for(auto const & string : boost::adaptors::reverse(searchPaths))
+	{
+		if (translator.load(string))
+		{
+			if (!qApp->installTranslator(&translator))
+				logGlobal->error("Failed to install translator");
+			return;
+		}
+	}
+
+	logGlobal->error("Failed to find translation");
 #endif
 }