diff --git a/Linphone/core/App.cpp b/Linphone/core/App.cpp index 8e92bc541..52dc27e0e 100644 --- a/Linphone/core/App.cpp +++ b/Linphone/core/App.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include "core/account/AccountCore.hpp" #include "core/account/AccountDeviceGui.hpp" @@ -479,6 +480,7 @@ void App::initCore() { setQuitOnLastWindowClosed(mSettings->getExitOnClose()); connect(mSettings.get(), &SettingsCore::exitOnCloseChanged, this, &App::onExitOnCloseChanged, Qt::UniqueConnection); + setLocale(settings->getConfigLocale()); const QUrl url(u"qrc:/Linphone/view/Page/Window/Main/MainWindow.qml"_qs); QObject::connect( @@ -510,6 +512,10 @@ void App::initCore() { mustBeInMainThread(log().arg(Q_FUNC_INFO)); setAutoStart(mSettings->getAutoStart()); }); + QObject::connect(mSettings.get(), &SettingsCore::configLocaleChanged, [this]() { + mustBeInMainThread(log().arg(Q_FUNC_INFO)); + setLocale(mSettings->getConfigLocale()); + }); mEngine->load(url); }); // coreModel.reset(); @@ -948,3 +954,15 @@ void App::setSysTrayIcon() { if (!mSystemTrayIcon) mSystemTrayIcon = systemTrayIcon; if (!QSystemTrayIcon::isSystemTrayAvailable()) qInfo() << "System tray is not available"; } + +//----------------------------------------------------------- +// Locale TODO - App only in French now. +//----------------------------------------------------------- + +void App::setLocale(QString configLocale) { + mLocale = QLocale(QLocale::French); +} + +QLocale App::getLocale() { + return mLocale; +} diff --git a/Linphone/core/App.hpp b/Linphone/core/App.hpp index 39ac39240..1a762b95b 100644 --- a/Linphone/core/App.hpp +++ b/Linphone/core/App.hpp @@ -108,6 +108,7 @@ public: void restart(); bool autoStartEnabled(); void setSysTrayIcon(); + QLocale getLocale(); void onLoggerInitialized(); void sendCommand(); @@ -145,6 +146,7 @@ signals: private: void createCommandParser(); void setAutoStart(bool enabled); + void setLocale(QString configLocale); QCommandLineParser *mParser = nullptr; Thread *mLinphoneThread = nullptr; @@ -158,6 +160,7 @@ private: QSharedPointer> mCoreModelConnection; QSharedPointer> mCliModelConnection; bool mAutoStart = false; + QLocale mLocale = QLocale::system(); DECLARE_ABSTRACT_OBJECT }; diff --git a/Linphone/core/setting/SettingsCore.cpp b/Linphone/core/setting/SettingsCore.cpp index bc130c10c..47f44a4df 100644 --- a/Linphone/core/setting/SettingsCore.cpp +++ b/Linphone/core/setting/SettingsCore.cpp @@ -97,6 +97,7 @@ SettingsCore::SettingsCore(QObject *parent) : QObject(parent) { INIT_CORE_MEMBER(ExitOnClose, settingsModel) INIT_CORE_MEMBER(SyncLdapContacts, settingsModel) INIT_CORE_MEMBER(Ipv6Enabled, settingsModel) + INIT_CORE_MEMBER(ConfigLocale, settingsModel) } SettingsCore::~SettingsCore() { @@ -345,6 +346,8 @@ void SettingsCore::setSelf(QSharedPointer me) { syncLdapContacts, SyncLdapContacts) DEFINE_CORE_GETSET_CONNECT(mSettingsModelConnection, SettingsCore, SettingsModel, settingsModel, bool, ipv6Enabled, Ipv6Enabled) + DEFINE_CORE_GETSET_CONNECT(mSettingsModelConnection, SettingsCore, SettingsModel, settingsModel, QString, + configLocale, ConfigLocale) auto coreModelConnection = QSharedPointer>( new SafeConnection(me, CoreModel::getInstance()), &QObject::deleteLater); @@ -516,3 +519,7 @@ bool SettingsCore::getExitOnClose() const { bool SettingsCore::getSyncLdapContacts() const { return mSyncLdapContacts; } + +QString SettingsCore::getConfigLocale() const { + return mConfigLocale; +} diff --git a/Linphone/core/setting/SettingsCore.hpp b/Linphone/core/setting/SettingsCore.hpp index 2139eeefd..0b9e9e805 100644 --- a/Linphone/core/setting/SettingsCore.hpp +++ b/Linphone/core/setting/SettingsCore.hpp @@ -167,6 +167,7 @@ public: DECLARE_CORE_GETSET_MEMBER(bool, ipv6Enabled, Ipv6Enabled) DECLARE_CORE_GETSET_MEMBER(QVariantList, audioCodecs, AudioCodecs) DECLARE_CORE_GETSET_MEMBER(QVariantList, videoCodecs, VideoCodecs) + DECLARE_CORE_GETSET(QString, configLocale, ConfigLocale) signals: diff --git a/Linphone/main.cpp b/Linphone/main.cpp index 7a0dddd8d..3c00d0670 100644 --- a/Linphone/main.cpp +++ b/Linphone/main.cpp @@ -55,16 +55,6 @@ int main(int argc, char *argv[]) { auto app = QSharedPointer::create(argc, argv); - QTranslator translator; - const QStringList uiLanguages = QLocale::system().uiLanguages(); - for (const QString &locale : uiLanguages) { - const QString baseName = "Linphone_" + QLocale(locale).name(); - if (translator.load(":/i18n/" + baseName)) { - app->installTranslator(&translator); - break; - } - } - #ifdef ACCESSBILITY_WORKAROUND QAccessible::installUpdateHandler(DummyUpdateHandler); QAccessible::installRootObjectHandler(DummyRootObjectHandler); diff --git a/Linphone/model/setting/SettingsModel.cpp b/Linphone/model/setting/SettingsModel.cpp index 2e0f17221..697c2d865 100644 --- a/Linphone/model/setting/SettingsModel.cpp +++ b/Linphone/model/setting/SettingsModel.cpp @@ -582,6 +582,7 @@ void SettingsModel::notifyConfigReady(){ DEFINE_NOTIFY_CONFIG_READY(autoStart, AutoStart) DEFINE_NOTIFY_CONFIG_READY(exitOnClose, ExitOnClose) DEFINE_NOTIFY_CONFIG_READY(syncLdapContacts, SyncLdapContacts) + DEFINE_NOTIFY_CONFIG_READY(configLocale, ConfigLocale) } DEFINE_GETSET_CONFIG(SettingsModel, bool, Bool, disableChatFeature, DisableChatFeature, "disable_chat_feature", true) @@ -679,4 +680,9 @@ DEFINE_GETSET_CONFIG(SettingsModel, SyncLdapContacts, "sync_ldap_contacts", false) +DEFINE_GETSET_CONFIG_STRING(SettingsModel, + configLocale, + ConfigLocale, + "locale", + "") // clang-format on diff --git a/Linphone/model/setting/SettingsModel.hpp b/Linphone/model/setting/SettingsModel.hpp index e30ef19ac..19d1028a8 100644 --- a/Linphone/model/setting/SettingsModel.hpp +++ b/Linphone/model/setting/SettingsModel.hpp @@ -154,6 +154,7 @@ public: DECLARE_GETSET(bool, exitOnClose, ExitOnClose) DECLARE_GETSET(bool, syncLdapContacts, SyncLdapContacts) DECLARE_GETSET(bool, ipv6Enabled, Ipv6Enabled) + DECLARE_GETSET(QString, configLocale, ConfigLocale) signals: diff --git a/Linphone/tool/Utils.cpp b/Linphone/tool/Utils.cpp index 9842cb5e8..e8ce15d20 100644 --- a/Linphone/tool/Utils.cpp +++ b/Linphone/tool/Utils.cpp @@ -264,7 +264,7 @@ QString Utils::formatDate(const QDateTime &date, bool includeTime) { else if (date.date() == QDate::currentDate().addDays(-1)) dateDay = tr("Hier"); else { QString format = date.date().year() == QDateTime::currentDateTime().date().year() ? "dd MMMM" : "dd MMMM yyyy"; - dateDay = tr(date.date().toString(format).toLocal8Bit().data()); + dateDay = App::getInstance()->getLocale().toString(date.date(), format); } if (!includeTime) return dateDay;