Merge branch 'translate-configs'

Use regular translation machinery to support and help out translations
from the config files. This reduces the need to do all the translation
in those files -- some of it can be shared with the regular TX workflow.
main
Adriaan de Groot 5 years ago
commit 790fbb96d5

@ -23,6 +23,7 @@
#include "utils/Logger.h" #include "utils/Logger.h"
#include "utils/Variant.h" #include "utils/Variant.h"
#include <QCoreApplication>
#include <QRegularExpression> #include <QRegularExpression>
#include <QRegularExpressionMatch> #include <QRegularExpressionMatch>
@ -34,7 +35,9 @@ TranslatedString::TranslatedString( const QString& string )
{ {
m_strings[ 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 // Get the un-decorated value for the key
QString value = CalamaresUtils::getString( map, 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;
}
} }

@ -39,8 +39,19 @@ class DLLEXPORT TranslatedString
{ {
public: public:
/** @brief Get all the translations connected to @p key /** @brief Get all the translations connected to @p key
*
* Gets map[key] as the "untranslated" form, and then all the
* keys of the form <key>[lang] are taken as the translation
* for <lang> 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. /** @brief Not-actually-translated string.
*/ */
TranslatedString( const QString& string ); TranslatedString( const QString& string );
@ -73,6 +84,7 @@ public:
private: private:
// Maps locale name to human-readable string, "" is English // Maps locale name to human-readable string, "" is English
QMap< QString, QString > m_strings; QMap< QString, QString > m_strings;
const char* m_context = nullptr;
}; };
} // namespace Locale } // namespace Locale
} // namespace CalamaresUtils } // namespace CalamaresUtils

@ -55,6 +55,17 @@ QString
NetInstallViewStep::prettyName() const NetInstallViewStep::prettyName() const
{ {
return m_sidebarLabel ? m_sidebarLabel->get() : tr( "Package selection" ); 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" ) ) 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" ) ) if ( label.contains( "title" ) )
{ {
m_widget->setPageTitle( new CalamaresUtils::Locale::TranslatedString( label, "title" ) ); m_widget->setPageTitle(
new CalamaresUtils::Locale::TranslatedString( label, "title", metaObject()->className() ) );
} }
} }

@ -30,8 +30,19 @@ required: false
# If no *sidebar* values are provided, defaults to "Package selection" # If no *sidebar* values are provided, defaults to "Package selection"
# and existing translations. If no *title* values are provided, no string # and existing translations. If no *title* values are provided, no string
# is displayed. # 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: label:
sidebar: "Package selection" sidebar: "Package selection"
sidebar[nl]: "Pakketkeuze" # sidebar[nl]: "Pakketkeuze"
title: "Office Package" # title: "Office Package"
title[nl]: "Kantoorsoftware" # title[nl]: "Kantoorsoftware"

Loading…
Cancel
Save