diff --git a/src/libcalamares/locale/Translation.h b/src/libcalamares/locale/Translation.h index 784c8652e..912a509ac 100644 --- a/src/libcalamares/locale/Translation.h +++ b/src/libcalamares/locale/Translation.h @@ -117,6 +117,11 @@ operator<<( QDebug& s, const Translation::Id& id ) { return s << id.name; } +static inline bool +operator==( const Translation::Id& lhs, const Translation::Id& rhs ) +{ + return lhs.name == rhs.name; +} } // namespace Locale } // namespace CalamaresUtils diff --git a/src/libcalamares/locale/TranslationsModel.cpp b/src/libcalamares/locale/TranslationsModel.cpp index 25d075df4..0ffa6f9c5 100644 --- a/src/libcalamares/locale/TranslationsModel.cpp +++ b/src/libcalamares/locale/TranslationsModel.cpp @@ -103,13 +103,13 @@ TranslationsModel::find( std::function< bool( const Translation& ) > predicate ) int TranslationsModel::find( std::function< bool( const QLocale& ) > predicate ) const { - return find( [&]( const Translation& l ) { return predicate( l.locale() ); } ); + return find( [ & ]( const Translation& l ) { return predicate( l.locale() ); } ); } int TranslationsModel::find( const QLocale& locale ) const { - return find( [&]( const Translation& l ) { return locale == l.locale(); } ); + return find( [ & ]( const Translation& l ) { return locale == l.locale(); } ); } int @@ -121,13 +121,19 @@ TranslationsModel::find( const QString& countryCode ) const } auto c_l = countryData( countryCode ); - int r = find( - [&]( const Translation& l ) { return ( l.language() == c_l.second ) && ( l.country() == c_l.first ); } ); + int r = find( [ & ]( const Translation& l ) + { return ( l.language() == c_l.second ) && ( l.country() == c_l.first ); } ); if ( r >= 0 ) { return r; } - return find( [&]( const Translation& l ) { return l.language() == c_l.second; } ); + return find( [ & ]( const Translation& l ) { return l.language() == c_l.second; } ); +} + +int +TranslationsModel::find( const Translation::Id& id ) const +{ + return find( [ & ]( const Translation& l ) { return l.id() == id; } ); } TranslationsModel* diff --git a/src/libcalamares/locale/TranslationsModel.h b/src/libcalamares/locale/TranslationsModel.h index b87c00027..3cd7c61dc 100644 --- a/src/libcalamares/locale/TranslationsModel.h +++ b/src/libcalamares/locale/TranslationsModel.h @@ -63,6 +63,8 @@ public: int find( const QLocale& ) const; /// @brief Looks for an item that best matches the 2-letter country code int find( const QString& countryCode ) const; + /// @brief Looks up a translation Id + int find( const Translation::Id& id ) const; private: QVector< Translation* > m_locales;