diff --git a/src/modules/keyboard/KeyboardLayoutModel.cpp b/src/modules/keyboard/KeyboardLayoutModel.cpp index b8cb892f4..9be9c8ef9 100644 --- a/src/modules/keyboard/KeyboardLayoutModel.cpp +++ b/src/modules/keyboard/KeyboardLayoutModel.cpp @@ -11,9 +11,15 @@ #include "KeyboardLayoutModel.h" #include "utils/Logger.h" +#include "utils/RAII.h" +#include "utils/Retranslator.h" + +#include #include +static QTranslator* s_kbtranslator = nullptr; + XKBListModel::XKBListModel( QObject* parent ) : QAbstractListModel( parent ) { @@ -41,6 +47,11 @@ XKBListModel::data( const QModelIndex& index, int role ) const switch ( role ) { case LabelRole: + if ( s_kbtranslator && m_contextname ) + { + auto s = s_kbtranslator->translate( m_contextname, item.label.toUtf8().data() ); + cDebug() << "Translated" << item.label << "to" << s; + } return item.label; case KeyRole: return item.key; @@ -93,6 +104,8 @@ XKBListModel::setCurrentIndex( int index ) KeyboardModelsModel::KeyboardModelsModel( QObject* parent ) : XKBListModel( parent ) { + m_contextname = "kb_models"; + // The models map is from human-readable names (!) to xkb identifier const auto models = KeyboardGlobal::getKeyboardModels(); m_list.reserve( models.count() ); @@ -110,6 +123,10 @@ KeyboardModelsModel::KeyboardModelsModel( QObject* parent ) } cDebug() << "Loaded" << m_list.count() << "keyboard models"; + + CALAMARES_RETRANSLATE( if ( !s_kbtranslator ) { s_kbtranslator = new QTranslator; } cqDeleter d { s_kbtranslator }; + d.preserve + = CalamaresUtils::loadTranslator( QLocale(), QStringLiteral( "kb_" ), s_kbtranslator ); ) } @@ -207,6 +224,7 @@ KeyboardLayoutModel::currentIndex() const KeyboardVariantsModel::KeyboardVariantsModel( QObject* parent ) : XKBListModel( parent ) { + m_contextname = "kb_variants"; } void diff --git a/src/modules/keyboard/KeyboardLayoutModel.h b/src/modules/keyboard/KeyboardLayoutModel.h index 60747da55..9c83e41d8 100644 --- a/src/modules/keyboard/KeyboardLayoutModel.h +++ b/src/modules/keyboard/KeyboardLayoutModel.h @@ -21,7 +21,6 @@ * * This model acts like it has a single selection, as well. */ - class XKBListModel : public QAbstractListModel { Q_OBJECT @@ -70,6 +69,7 @@ protected: }; QVector< ModelInfo > m_list; int m_currentIndex = -1; + const char* m_contextname = nullptr; };