Use English as default translator if no translations are found

(cherry picked from commit 2ce0d8ae491c440672d86057c453f62b62465d89)
This commit is contained in:
Julien Wadel 2020-06-25 12:01:28 +00:00
parent 3dd6b95bee
commit 02d80855f8
3 changed files with 17 additions and 10 deletions

View file

@ -191,6 +191,7 @@ App::App (int &argc, char *argv[]) : SingleApplication(argc, argv, true, Mode::U
// Init locale.
mTranslator = new DefaultTranslator(this);
mDefaultTranslator = new DefaultTranslator(this);
initLocale(config);
if (mParser->isSet("help")) {
@ -255,7 +256,12 @@ void App::initContentApp () {
mSystemTrayIcon = nullptr;
CoreManager::uninit();
removeTranslator(mTranslator);
removeTranslator(mDefaultTranslator);
delete mTranslator;
delete mDefaultTranslator;
mTranslator = new DefaultTranslator(this);
mDefaultTranslator = new DefaultTranslator(this);
initLocale(config);
} else {
// Update and download codecs.
@ -622,6 +628,12 @@ void App::setTrayIcon () {
void App::initLocale (const shared_ptr<linphone::Config> &config) {
// Try to use preferred locale.
QString locale;
// Use english. This default translator is used if there are no found translations in others loads
mLocale = DefaultLocale;
if (!installLocale(*this, *mDefaultTranslator, QLocale(mLocale)))
qFatal("Unable to install default translator.");
if (config)
locale = Utils::coreStringToAppString(config->getString(SettingsModel::UiSection, "locale", ""));
@ -637,10 +649,6 @@ void App::initLocale (const shared_ptr<linphone::Config> &config) {
return;
}
// Use english.
mLocale = DefaultLocale;
if (!installLocale(*this, *mTranslator, QLocale(mLocale)))
qFatal("Unable to install default translator.");
}
QString App::getConfigLocale () const {

View file

@ -164,6 +164,7 @@ private:
QQmlApplicationEngine *mEngine = nullptr;
DefaultTranslator *mTranslator = nullptr;
DefaultTranslator *mDefaultTranslator = nullptr;
Notifier *mNotifier = nullptr;
QQuickWindow *mCallsWindow = nullptr;

View file

@ -44,9 +44,7 @@ DefaultTranslator::DefaultTranslator (QObject *parent) : QTranslator(parent) {
continue;
QString basename = info.baseName();
if (mContexts.contains(basename))
qWarning() << QStringLiteral("QML context `%1` already exists in contexts list.").arg(basename);
else
if (!mContexts.contains(basename))
mContexts << basename;
}
end:;
@ -65,8 +63,8 @@ QString DefaultTranslator::translate (
QString translation = QTranslator::translate(context, sourceText, disambiguation, n);
if (translation.length() == 0 && mContexts.contains(context))
qWarning() << QStringLiteral("Unable to find a translation. (context=%1, label=%2)")
.arg(context).arg(sourceText);
qWarning() << QStringLiteral("Unable to find a translation. (context=%1, label=%2, disambiguation=%3)")
.arg(context).arg(sourceText).arg(disambiguation);
return translation;
}