diff --git a/src/libcalamares/locale/TranslatableConfiguration.cpp b/src/libcalamares/locale/TranslatableConfiguration.cpp index bc39c398e..83199a4cc 100644 --- a/src/libcalamares/locale/TranslatableConfiguration.cpp +++ b/src/libcalamares/locale/TranslatableConfiguration.cpp @@ -23,6 +23,7 @@ #include "utils/Logger.h" #include "utils/Variant.h" +#include #include #include @@ -34,7 +35,9 @@ TranslatedString::TranslatedString( const QString& string ) { m_strings[ QString() ] = string; } -TranslatedString::TranslatedString( const QVariantMap& map, const QString& key ) + +TranslatedString::TranslatedString( const QVariantMap& map, const QString& key, const char* context ) + : m_context( context ) { // Get the un-decorated value for the key QString value = CalamaresUtils::getString( map, key ); @@ -99,7 +102,17 @@ TranslatedString::get( const QLocale& locale ) const } } - return m_strings[ QString() ]; + // If we're given a context to work with, also try the same string in + // the regular translation framework. + const QString& s = m_strings[ QString() ]; + if ( m_context ) + { + return QCoreApplication::translate( m_context, s.toLatin1().constData() ); + } + else + { + return s; + } } diff --git a/src/libcalamares/locale/TranslatableConfiguration.h b/src/libcalamares/locale/TranslatableConfiguration.h index 45679bce0..d845569bc 100644 --- a/src/libcalamares/locale/TranslatableConfiguration.h +++ b/src/libcalamares/locale/TranslatableConfiguration.h @@ -39,8 +39,19 @@ class DLLEXPORT TranslatedString { public: /** @brief Get all the translations connected to @p key + * + * Gets map[key] as the "untranslated" form, and then all the + * keys of the form [lang] are taken as the translation + * for of the untranslated form. + * + * If @p context is not a nullptr, then that is taken as an + * indication to **also** use the regular QObject::tr() translation + * mechanism for these strings. It is recommended to pass in + * metaObject()->className() as context (from a QObject based class) + * to give the TranslatedString the same context as other calls + * to tr() within that class. */ - TranslatedString( const QVariantMap& map, const QString& key ); + TranslatedString( const QVariantMap& map, const QString& key, const char* context = nullptr ); /** @brief Not-actually-translated string. */ TranslatedString( const QString& string ); @@ -73,6 +84,7 @@ public: private: // Maps locale name to human-readable string, "" is English QMap< QString, QString > m_strings; + const char* m_context = nullptr; }; } // namespace Locale } // namespace CalamaresUtils diff --git a/src/modules/netinstall/NetInstallViewStep.cpp b/src/modules/netinstall/NetInstallViewStep.cpp index 3227ecd65..8de3fd74f 100644 --- a/src/modules/netinstall/NetInstallViewStep.cpp +++ b/src/modules/netinstall/NetInstallViewStep.cpp @@ -55,6 +55,17 @@ QString NetInstallViewStep::prettyName() const { return m_sidebarLabel ? m_sidebarLabel->get() : tr( "Package selection" ); + + // This is a table of "standard" labels for this module. If you use them + // in the label: sidebar: section of the config file, the existing + // translations can be used. + NOTREACHED + tr( "Package selection" ); + tr( "Office software" ); + tr( "Office package" ); + tr( "Browser software" ); + tr( "Browser package" ); + tr( "Web browser" ); } @@ -199,10 +210,11 @@ NetInstallViewStep::setConfigurationMap( const QVariantMap& configurationMap ) if ( label.contains( "sidebar" ) ) { - m_sidebarLabel = new CalamaresUtils::Locale::TranslatedString( label, "sidebar" ); + m_sidebarLabel = new CalamaresUtils::Locale::TranslatedString( label, "sidebar", metaObject()->className() ); } if ( label.contains( "title" ) ) { - m_widget->setPageTitle( new CalamaresUtils::Locale::TranslatedString( label, "title" ) ); + m_widget->setPageTitle( + new CalamaresUtils::Locale::TranslatedString( label, "title", metaObject()->className() ) ); } } diff --git a/src/modules/netinstall/netinstall.conf b/src/modules/netinstall/netinstall.conf index ab600326e..5f90fec76 100644 --- a/src/modules/netinstall/netinstall.conf +++ b/src/modules/netinstall/netinstall.conf @@ -30,8 +30,19 @@ required: false # If no *sidebar* values are provided, defaults to "Package selection" # and existing translations. If no *title* values are provided, no string # is displayed. +# +# The following strings are already known to Calamares and can be +# listed here in *untranslated* form (e.g. as value of *sidebar*) +# without bothering with the translations: they are picked up from +# the regular translation framework: +# - "Package selection" +# - "Office software" +# - "Office package" +# - "Browser software" +# - "Browser package" +# - "Web browser" label: sidebar: "Package selection" - sidebar[nl]: "Pakketkeuze" - title: "Office Package" - title[nl]: "Kantoorsoftware" + # sidebar[nl]: "Pakketkeuze" + # title: "Office Package" + # title[nl]: "Kantoorsoftware"