GUI: assure UI language is a known one

Fixes #1434.
This commit is contained in:
Moritz Bunkus 2015-09-20 19:18:18 +02:00
parent d5a0213ce6
commit d1405b2e5b
5 changed files with 44 additions and 28 deletions

View File

@ -1,5 +1,9 @@
2015-09-20 Moritz Bunkus <moritz@bunkus.org>
* MKVToolNix GUI: bug fix: the interface language selection has
been improved not to select wrong entries resulting in error
messages from mkvmerge about unknown translations. Fixes #1434.
* MKVToolNix GUI: bug fix: if the Windows version of the GUI was
started from a symbolically linked folder then it would crash when
the user added a file. Fixes #1315.

View File

@ -12,7 +12,6 @@
#include "common/fs_sys_helpers.h"
#include "common/iso639.h"
#include "common/qt.h"
#include "common/translation.h"
#include "common/unique_numbers.h"
#include "common/version.h"
#include "mkvtoolnix-gui/app.h"
@ -254,47 +253,31 @@ App::isInstalled() {
void
App::initializeLocale(QString const &requestedLocale) {
auto locale = to_utf8(requestedLocale);
auto locale = Util::Settings::get().localeToUse(requestedLocale);
#if defined(HAVE_LIBINTL_H)
auto &cfg = Util::Settings::get();
if (!locale.isEmpty()) {
if (m_currentTranslator)
removeTranslator(m_currentTranslator.get());
m_currentTranslator.reset();
if (m_currentTranslator)
removeTranslator(m_currentTranslator.get());
m_currentTranslator.reset();
translation_c::initialize_available_translations();
if (locale.empty())
locale = to_utf8(cfg.m_uiLocale);
if (-1 == translation_c::look_up_translation(locale))
locale = "";
if (locale.empty()) {
locale = boost::regex_replace(translation_c::get_default_ui_locale(), boost::regex{"\\..*", boost::regex::perl}, "");
if (-1 == translation_c::look_up_translation(locale))
locale = "";
}
if (!locale.empty()) {
auto translator = std::make_unique<QTranslator>();
auto paths = QStringList{} << Q("%1/locale/%2/LC_MESSAGES").arg(applicationDirPath()).arg(Q(locale))
auto paths = QStringList{} << Q("%1/locale/%2/LC_MESSAGES").arg(applicationDirPath()).arg(locale)
<< QLibraryInfo::location(QLibraryInfo::TranslationsPath);
for (auto const &path : paths)
if (translator->load(Q("qtbase_%1").arg(Q(locale)), path))
if (translator->load(Q("qtbase_%1").arg(locale), path))
break;
installTranslator(translator.get());
m_currentTranslator = std::move(translator);
cfg.m_uiLocale = Q(locale);
m_currentTranslator = std::move(translator);
Util::Settings::get().m_uiLocale = locale;
}
#endif // HAVE_LIBINTL_H
init_locales(locale);
init_locales(to_utf8(locale));
retranslateUi();
}

View File

@ -395,8 +395,10 @@ MuxConfig::buildMkvmergeOptions()
auto options = QStringList{};
auto &settings = Util::Settings::get();
auto locale = settings.localeToUse();
options << Q("--ui-language") << settings.m_uiLocale;
if (!locale.isEmpty())
options << Q("--ui-language") << locale;
if (Util::Settings::NormalPriority != settings.m_priority)
options << Q("--priority") << settings.priorityAsString();

View File

@ -396,4 +396,27 @@ Settings::storeSplitterSizes() {
qDebug() << "storeSplitterSize() signal from non-splitter" << sender() << sender()->objectName();
}
QString
Settings::localeToUse(QString const &requestedLocale) {
auto locale = to_utf8(requestedLocale);
#if defined(HAVE_LIBINTL_H)
translation_c::initialize_available_translations();
if (locale.empty())
locale = to_utf8(m_uiLocale);
if (-1 == translation_c::look_up_translation(locale))
locale = "";
if (locale.empty()) {
locale = boost::regex_replace(translation_c::get_default_ui_locale(), boost::regex{"\\..*", boost::regex::perl}, "");
if (-1 == translation_c::look_up_translation(locale))
locale = "";
}
#endif
return to_qs(locale);
}
}}}

View File

@ -9,6 +9,8 @@
#include <QTabWidget>
#include <QVariant>
#include "common/translation.h"
class QSettings;
class QSplitter;
@ -106,6 +108,8 @@ public:
void handleSplitterSizes(QSplitter *splitter);
void restoreSplitterSizes(QSplitter *splitter);
QString localeToUse(QString const &requestedLocale = {});
public slots:
void storeSplitterSizes();