[libcalamares] Support looking up translation by 2-letter country
- Looks for an available translation by 2-letter country code and returns the row for it.
This commit is contained in:
parent
1857952431
commit
03f88b3ed6
@ -92,6 +92,18 @@ public:
|
|||||||
return m_locale.name();
|
return m_locale.name();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Convenience accessor to the language part of the locale
|
||||||
|
QLocale::Language language() const
|
||||||
|
{
|
||||||
|
return m_locale.language();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @brief Convenience accessor to the country part (if any) of the locale
|
||||||
|
QLocale::Country country() const
|
||||||
|
{
|
||||||
|
return m_locale.country();
|
||||||
|
}
|
||||||
|
|
||||||
/** @brief Get a Qt locale for the given @p localeName
|
/** @brief Get a Qt locale for the given @p localeName
|
||||||
*
|
*
|
||||||
* This special-cases `sr@latin`, which is used as a translation
|
* This special-cases `sr@latin`, which is used as a translation
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
|
|
||||||
#include "LabelModel.h"
|
#include "LabelModel.h"
|
||||||
|
|
||||||
|
#include "Lookup.h"
|
||||||
|
|
||||||
#include "CalamaresVersion.h" // For the list of translations
|
#include "CalamaresVersion.h" // For the list of translations
|
||||||
|
|
||||||
namespace CalamaresUtils::Locale
|
namespace CalamaresUtils::Locale
|
||||||
@ -106,6 +108,19 @@ LabelModel::find( const QLocale& locale ) const
|
|||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
LabelModel::find( const QString& countryCode ) const
|
||||||
|
{
|
||||||
|
if ( countryCode.length() != 2 )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
auto c_l = countryData( countryCode );
|
||||||
|
int r = find( [&]( const Label& l ){ return ( l.language() == c_l.second ) && ( l.country() == c_l.first ); } );
|
||||||
|
if ( r >= 0 )
|
||||||
|
return r;
|
||||||
|
return find( [&]( const Label& l ){ return l.language() == c_l.second; } );
|
||||||
|
}
|
||||||
|
|
||||||
LabelModel* const availableTranslations()
|
LabelModel* const availableTranslations()
|
||||||
{
|
{
|
||||||
static LabelModel model( QString( CALAMARES_TRANSLATION_LANGUAGES ).split( ';') );
|
static LabelModel model( QString( CALAMARES_TRANSLATION_LANGUAGES ).split( ';') );
|
||||||
|
@ -59,7 +59,10 @@ public:
|
|||||||
*/
|
*/
|
||||||
int find( std::function<bool( const QLocale& )> predicate ) const;
|
int find( std::function<bool( const QLocale& )> predicate ) const;
|
||||||
int find( std::function<bool( const Label& )> predicate ) const;
|
int find( std::function<bool( const Label& )> predicate ) const;
|
||||||
|
/// @brief Looks for an item using the same locale, -1 if there isn't one
|
||||||
int find( const QLocale& ) const;
|
int find( const QLocale& ) const;
|
||||||
|
/// @brief Looks for an item that best matches the 2-letter country code
|
||||||
|
int find( const QString& countryCode ) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVector< Label > m_locales;
|
QVector< Label > m_locales;
|
||||||
|
Loading…
Reference in New Issue
Block a user