From 21f97db8fd95265ad9eada8f807673428b3350ce Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 6 Aug 2020 14:19:27 +0200 Subject: [PATCH] [libcalamares] Offer translation lookup of regions --- src/libcalamares/locale/TimeZone.cpp | 12 ++++++++++++ src/libcalamares/locale/TimeZone.h | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/libcalamares/locale/TimeZone.cpp b/src/libcalamares/locale/TimeZone.cpp index 364564232..e2779281f 100644 --- a/src/libcalamares/locale/TimeZone.cpp +++ b/src/libcalamares/locale/TimeZone.cpp @@ -268,6 +268,18 @@ RegionsModel::roleNames() const return { { NameRole, "name" }, { KeyRole, "key" } }; } +QString +RegionsModel::tr( const QString& region ) const +{ + for ( const auto* p : m_private->m_regions ) + { + if ( p->key() == region ) + { + return p->tr(); + } + } + return region; +} ZonesModel::ZonesModel( QObject* parent ) : QAbstractListModel( parent ) diff --git a/src/libcalamares/locale/TimeZone.h b/src/libcalamares/locale/TimeZone.h index 1a4ee03bf..1d4b4a8ff 100644 --- a/src/libcalamares/locale/TimeZone.h +++ b/src/libcalamares/locale/TimeZone.h @@ -47,6 +47,9 @@ class TimeZoneData : public QObject, TranslatableString Q_OBJECT Q_PROPERTY( QString region READ region CONSTANT ) + Q_PROPERTY( QString zone READ zone CONSTANT ) + Q_PROPERTY( QString name READ tr CONSTANT ) + Q_PROPERTY( QString countryCode READ country CONSTANT ) public: TimeZoneData( const QString& region, @@ -98,6 +101,14 @@ public: QHash< int, QByteArray > roleNames() const override; +public Q_SLOTS: + /** @brief Provides a human-readable version of the region + * + * Returns @p region unchanged if there is no such region + * or no translation for the region's name. + */ + QString tr( const QString& region ) const; + private: Private* m_private; };