[libcalamares] Offer translation lookup of regions

This commit is contained in:
Adriaan de Groot 2020-08-06 14:19:27 +02:00
parent ad3c0de936
commit 21f97db8fd
2 changed files with 23 additions and 0 deletions

View File

@ -268,6 +268,18 @@ RegionsModel::roleNames() const
return { { NameRole, "name" }, { KeyRole, "key" } }; 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 ) ZonesModel::ZonesModel( QObject* parent )
: QAbstractListModel( parent ) : QAbstractListModel( parent )

View File

@ -47,6 +47,9 @@ class TimeZoneData : public QObject, TranslatableString
Q_OBJECT Q_OBJECT
Q_PROPERTY( QString region READ region CONSTANT ) 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: public:
TimeZoneData( const QString& region, TimeZoneData( const QString& region,
@ -98,6 +101,14 @@ public:
QHash< int, QByteArray > roleNames() const override; 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:
Private* m_private; Private* m_private;
}; };