From 7beddef3371932c13389b25ab93c180fb690673a Mon Sep 17 00:00:00 2001 From: wangfei Date: Mon, 22 Jan 2024 11:00:16 +0800 Subject: [PATCH] fix: no translation for time in greeter Set locale to the current user's locale when firstly entering system Issue: https://github.com/linuxdeepin/developer-center/issues/6994 --- src/session-widgets/lockcontent.cpp | 5 ++++- src/widgets/timewidget.cpp | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/session-widgets/lockcontent.cpp b/src/session-widgets/lockcontent.cpp index 6a2367ae..1dc92528 100644 --- a/src/session-widgets/lockcontent.cpp +++ b/src/session-widgets/lockcontent.cpp @@ -78,6 +78,9 @@ LockContent::LockContent(SessionBaseModel *const model, QWidget *parent) } } once = true; + + QString localeName = regionValue(localeName_key); + m_timeWidget->updateLocale(QLocale(localeName)); } void LockContent::initUI() @@ -294,7 +297,7 @@ void LockContent::onCurrentUserChanged(std::shared_ptr user) m_user = user; m_localeName = regionValue(localeName_key); - QLocale locale = m_localeName.isEmpty()? QLocale::system() : QLocale(m_localeName); + QLocale locale = m_localeName.isEmpty()? user->locale() : QLocale(m_localeName); m_shortTimeFormat = regionValue(shortTimeFormat_key); m_longDateFormat = regionValue(longDateFormat_key); buildConnect(); diff --git a/src/widgets/timewidget.cpp b/src/widgets/timewidget.cpp index 1e81914c..657c89c9 100644 --- a/src/widgets/timewidget.cpp +++ b/src/widgets/timewidget.cpp @@ -63,7 +63,7 @@ void TimeWidget::set24HourFormat(bool use24HourFormat) void TimeWidget::updateLocale(const QLocale &locale, const QString &shortTimeFormat, const QString &longDateFormat) { - m_locale = locale; + m_locale = locale.name().isEmpty() ? QLocale::system() : locale; if (!shortTimeFormat.isEmpty()) m_shortTimeFormat = shortTimeFormat; if (!longDateFormat.isEmpty())