fix: show proper error if language file loading fails

closes #89
Dieser Commit ist enthalten in:
Reinder Feenstra 2023-11-23 23:09:46 +01:00
Ursprung e4666e3fae
Commit 12e23c90a9
3 geänderte Dateien mit 30 neuen und 7 gelöschten Zeilen

Datei anzeigen

@ -25,6 +25,7 @@
#include <QSettings>
#endif
#include <QCommandLineParser>
#include <QMessageBox>
#include <version.hpp>
#include "mainwindow.hpp"
#include "settings/generalsettings.hpp"
@ -100,15 +101,25 @@ int main(int argc, char* argv[])
const bool logMissingStrings = !DeveloperSettings::instance().logMissingStringsDir.value().isEmpty();
const auto localePath = getLocalePath();
Locale::instance = std::make_unique<Locale>(localePath / "neutral.lang");
if(language != languageDefault && !DeveloperSettings::instance().dontLoadFallbackLanguage)
try
{
Locale::instance = std::make_unique<Locale>(localePath / languageDefault.toStdString().append(".lang"), std::move(Locale::instance));
if(logMissingStrings)
const_cast<Locale*>(Locale::instance.get())->enableMissingLogging();
Locale::instance = std::make_unique<Locale>(localePath / "neutral.lang");
if(language != languageDefault && !DeveloperSettings::instance().dontLoadFallbackLanguage)
{
Locale::instance = std::make_unique<Locale>(localePath / languageDefault.toStdString().append(".lang"), std::move(Locale::instance));
if(logMissingStrings)
const_cast<Locale*>(Locale::instance.get())->enableMissingLogging();
}
Locale::instance = std::make_unique<Locale>(localePath / language.toStdString().append(".lang"), std::move(Locale::instance));
}
catch(const std::exception& e)
{
QMessageBox::critical(nullptr, "Error", QString::fromLatin1(e.what()));
return EXIT_FAILURE;
}
Locale::instance = std::make_unique<Locale>(localePath / language.toStdString().append(".lang"), std::move(Locale::instance));
if(logMissingStrings)
const_cast<Locale*>(Locale::instance.get())->enableMissingLogging();

Datei anzeigen

@ -87,7 +87,15 @@ int main(int argc, char* argv[])
#endif
const auto localePath = getLocalePath();
Locale::instance = std::make_unique<Locale>(localePath / "en-us.lang", std::make_unique<Locale>(localePath / "neutral.lang"));
try
{
Locale::instance = std::make_unique<Locale>(localePath / "en-us.lang", std::make_unique<Locale>(localePath / "neutral.lang"));
}
catch(const std::exception& e)
{
std::cerr << e.what() << std::endl;
exit(EXIT_FAILURE);
}
if(enableConsoleLogger)
Log::enableConsoleLogger();

Datei anzeigen

@ -61,6 +61,10 @@ Locale::Locale(std::filesystem::path _filename, std::unique_ptr<const Locale> fa
p += 4 - (len % 4);
}
}
else
{
throw std::runtime_error(std::string("Failed loading language file: ").append(filename.string()));
}
}
void Locale::enableMissingLogging()