From 0eae72e10f04047fbb979196d9b2f4c552daa3f3 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 2 Sep 2019 14:45:20 +0200 Subject: [PATCH 1/2] [packagechooser] Introduce translatable labels - Since the package chooser might be used more than once, or for more specific items than "Packages", introduce a way to provide specific strings for display. - The only string needed is the ViewStep name, since the item with id "" can be used for the no-selection item. --- src/modules/packagechooser/packagechooser.conf | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/modules/packagechooser/packagechooser.conf b/src/modules/packagechooser/packagechooser.conf index eebe4dfb4..b82a52d3f 100644 --- a/src/modules/packagechooser/packagechooser.conf +++ b/src/modules/packagechooser/packagechooser.conf @@ -20,6 +20,19 @@ # or one-or-more). mode: required +# Human-visible strings in this module. These are all optional. +# The following translated keys are used: +# - *step*, used in the overall progress view (left-hand pane) +# +# Each key kan have a [locale] added to it, which is used as +# the translated string for that locale. For the strings +# associated with the "no-selection" item, see *items*, below +# with the explicit id "". +# +labels: + step: "Packages" + step[nl]: "Pakketten" + # Items to display in the chooser. In general, this should be a # pretty short list to avoid overwhelming the UI. This is a list # of objects, and the items are displayed in list order. From 019d1c36c69344872ad069af3d4d4d7a49532aab Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 2 Sep 2019 15:13:51 +0200 Subject: [PATCH 2/2] [packagechooser] Load translated strings from config - Apply the *labels* from the configuration file to the visible strings (only the ViewStep name). --- .../packagechooser/PackageChooserViewStep.cpp | 21 +++++++++++++++---- .../packagechooser/PackageChooserViewStep.h | 2 ++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/modules/packagechooser/PackageChooserViewStep.cpp b/src/modules/packagechooser/PackageChooserViewStep.cpp index 7758986ba..6b014fda2 100644 --- a/src/modules/packagechooser/PackageChooserViewStep.cpp +++ b/src/modules/packagechooser/PackageChooserViewStep.cpp @@ -32,6 +32,7 @@ #include "GlobalStorage.h" #include "JobQueue.h" +#include "locale/TranslatableConfiguration.h" #include "utils/CalamaresUtilsSystem.h" #include "utils/Logger.h" #include "utils/Variant.h" @@ -46,6 +47,7 @@ PackageChooserViewStep::PackageChooserViewStep( QObject* parent ) , m_widget( nullptr ) , m_model( nullptr ) , m_mode( PackageChooserMode::Required ) + , m_stepName( nullptr ) { emit nextStatusChanged( false ); } @@ -58,13 +60,14 @@ PackageChooserViewStep::~PackageChooserViewStep() m_widget->deleteLater(); } delete m_model; + delete m_stepName; } QString PackageChooserViewStep::prettyName() const { - return tr( "Packages" ); + return m_stepName ? m_stepName->get() : tr( "Packages" ); } @@ -167,12 +170,12 @@ void PackageChooserViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { QString mode = CalamaresUtils::getString( configurationMap, "mode" ); - bool ok = false; + bool mode_ok = false; if ( !mode.isEmpty() ) { - m_mode = roleNames().find( mode, ok ); + m_mode = roleNames().find( mode, mode_ok ); } - if ( !ok ) + if ( !mode_ok ) { m_mode = PackageChooserMode::Required; } @@ -185,6 +188,16 @@ PackageChooserViewStep::setConfigurationMap( const QVariantMap& configurationMap m_id = moduleInstanceKey().split( '@' ).last(); } + bool labels_ok = false; + auto labels = CalamaresUtils::getSubMap( configurationMap, "labels", labels_ok ); + if ( labels_ok ) + { + if ( labels.contains( "step" ) ) + { + m_stepName = new CalamaresUtils::Locale::TranslatedString( labels, "step" ); + } + } + bool first_time = !m_model; if ( configurationMap.contains( "items" ) ) { diff --git a/src/modules/packagechooser/PackageChooserViewStep.h b/src/modules/packagechooser/PackageChooserViewStep.h index e3ffc1d5b..da0775758 100644 --- a/src/modules/packagechooser/PackageChooserViewStep.h +++ b/src/modules/packagechooser/PackageChooserViewStep.h @@ -20,6 +20,7 @@ #define PACKAGECHOOSERVIEWSTEP_H #include "PluginDllMacro.h" +#include "locale/TranslatableConfiguration.h" #include "utils/PluginFactory.h" #include "viewpages/ViewStep.h" @@ -65,6 +66,7 @@ private: // Configuration PackageChooserMode m_mode; QString m_id; + CalamaresUtils::Locale::TranslatedString *m_stepName; // As it appears in the sidebar }; CALAMARES_PLUGIN_FACTORY_DECLARATION( PackageChooserViewStepFactory )