[libcalamares] Compare translation IDs, extend find()

Allow naive comparison of translation IDs (e.g. "ca@valencia"
against other IDs) and make it easier to find one.
This commit is contained in:
Adriaan de Groot 2022-05-04 10:35:43 +02:00
parent 5307976179
commit 792c4914b0
3 changed files with 18 additions and 5 deletions

View File

@ -117,6 +117,11 @@ operator<<( QDebug& s, const Translation::Id& id )
{ {
return s << id.name; return s << id.name;
} }
static inline bool
operator==( const Translation::Id& lhs, const Translation::Id& rhs )
{
return lhs.name == rhs.name;
}
} // namespace Locale } // namespace Locale
} // namespace CalamaresUtils } // namespace CalamaresUtils

View File

@ -121,8 +121,8 @@ TranslationsModel::find( const QString& countryCode ) const
} }
auto c_l = countryData( countryCode ); auto c_l = countryData( countryCode );
int r = find( int r = find( [ & ]( const Translation& l )
[&]( const Translation& l ) { return ( l.language() == c_l.second ) && ( l.country() == c_l.first ); } ); { return ( l.language() == c_l.second ) && ( l.country() == c_l.first ); } );
if ( r >= 0 ) if ( r >= 0 )
{ {
return r; return r;
@ -130,6 +130,12 @@ TranslationsModel::find( const QString& countryCode ) const
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* TranslationsModel*
availableTranslations() availableTranslations()
{ {

View File

@ -63,6 +63,8 @@ public:
int find( const QLocale& ) const; int find( const QLocale& ) const;
/// @brief Looks for an item that best matches the 2-letter country code /// @brief Looks for an item that best matches the 2-letter country code
int find( const QString& countryCode ) const; int find( const QString& countryCode ) const;
/// @brief Looks up a translation Id
int find( const Translation::Id& id ) const;
private: private:
QVector< Translation* > m_locales; QVector< Translation* > m_locales;