Merge branch 'refactor-translation' into calamares

This commit is contained in:
Adriaan de Groot 2021-09-07 15:35:43 +02:00
commit e11b42ce50
17 changed files with 129 additions and 127 deletions

View File

@ -78,7 +78,7 @@ CalamaresApplication::init()
initQmlPath(); initQmlPath();
initBranding(); initBranding();
CalamaresUtils::installTranslator( QLocale::system(), QString() ); CalamaresUtils::installTranslator();
setQuitOnLastWindowClosed( false ); setQuitOnLastWindowClosed( false );
setWindowIcon( QIcon( Calamares::Branding::instance()->imagePath( Calamares::Branding::ProductIcon ) ) ); setWindowIcon( QIcon( Calamares::Branding::instance()->imagePath( Calamares::Branding::ProductIcon ) ) );

View File

@ -40,12 +40,12 @@ set( libSources
# Locale-data service # Locale-data service
locale/Global.cpp locale/Global.cpp
locale/Label.cpp
locale/LabelModel.cpp
locale/Lookup.cpp locale/Lookup.cpp
locale/TimeZone.cpp locale/TimeZone.cpp
locale/TranslatableConfiguration.cpp locale/TranslatableConfiguration.cpp
locale/TranslatableString.cpp locale/TranslatableString.cpp
locale/Translation.cpp
locale/TranslationsModel.cpp
# Modules # Modules
modulesystem/Config.cpp modulesystem/Config.cpp

View File

@ -9,9 +9,9 @@
*/ */
#include "locale/Global.h" #include "locale/Global.h"
#include "locale/LabelModel.h"
#include "locale/TimeZone.h" #include "locale/TimeZone.h"
#include "locale/TranslatableConfiguration.h" #include "locale/TranslatableConfiguration.h"
#include "locale/TranslationsModel.h"
#include "CalamaresVersion.h" #include "CalamaresVersion.h"
#include "GlobalStorage.h" #include "GlobalStorage.h"

View File

@ -10,7 +10,7 @@
#include "TranslatableConfiguration.h" #include "TranslatableConfiguration.h"
#include "LabelModel.h" #include "TranslationsModel.h"
#include "utils/Logger.h" #include "utils/Logger.h"
#include "utils/Variant.h" #include "utils/Variant.h"
@ -69,6 +69,7 @@ TranslatedString::get() const
QString QString
TranslatedString::get( const QLocale& locale ) const TranslatedString::get( const QLocale& locale ) const
{ {
// TODO: keep track of special cases like sr@latin and ca@valencia
QString localeName = locale.name(); QString localeName = locale.name();
// Special case, sr@latin doesn't have the @latin reflected in the name // Special case, sr@latin doesn't have the @latin reflected in the name
if ( locale.language() == QLocale::Language::Serbian && locale.script() == QLocale::Script::LatinScript ) if ( locale.language() == QLocale::Language::Serbian && locale.script() == QLocale::Script::LatinScript )

View File

@ -9,7 +9,7 @@
* *
*/ */
#include "Label.h" #include "Translation.h"
#include <memory> #include <memory>
@ -25,8 +25,9 @@
* Returns a pair of nullptrs for non-special cases. * Returns a pair of nullptrs for non-special cases.
*/ */
static std::pair< QLocale*, QString* > static std::pair< QLocale*, QString* >
specialCase( const QString& localeName ) specialCase( const CalamaresUtils::Locale::Translation::Id& locale )
{ {
const QString localeName = locale.name;
if ( localeName == "sr@latin" ) if ( localeName == "sr@latin" )
{ {
static QLocale loc( QLocale::Language::Serbian, QLocale::Script::LatinScript, QLocale::Country::Serbia ); static QLocale loc( QLocale::Language::Serbian, QLocale::Script::LatinScript, QLocale::Country::Serbia );
@ -46,30 +47,30 @@ namespace CalamaresUtils
namespace Locale namespace Locale
{ {
Label::Label( QObject* parent ) Translation::Translation( QObject* parent )
: Label( QString(), LabelFormat::IfNeededWithCountry, parent ) : Translation( { QString() }, LabelFormat::IfNeededWithCountry, parent )
{ {
} }
Label::Label( const QString& locale, LabelFormat format, QObject* parent ) Translation::Translation( const Id& localeId, LabelFormat format, QObject* parent )
: QObject( parent ) : QObject( parent )
, m_locale( Label::getLocale( locale ) ) , m_locale( getLocale( localeId ) )
, m_localeId( locale.isEmpty() ? m_locale.name() : locale ) , m_localeId( localeId.name.isEmpty() ? m_locale.name() : localeId.name )
{ {
auto special = specialCase( locale ); auto [ _, name ] = specialCase( localeId );
QString longFormat = QObject::tr( "%1 (%2)" ); QString longFormat = QObject::tr( "%1 (%2)" );
QString languageName = special.second ? *special.second : m_locale.nativeLanguageName(); QString languageName = name ? *name : m_locale.nativeLanguageName();
QString englishName = m_locale.languageToString( m_locale.language() ); QString englishName = m_locale.languageToString( m_locale.language() );
if ( languageName.isEmpty() ) if ( languageName.isEmpty() )
{ {
languageName = QString( "* %1 (%2)" ).arg( locale, englishName ); languageName = QString( "* %1 (%2)" ).arg( localeId.name, englishName );
} }
bool needsCountryName = ( format == LabelFormat::AlwaysWithCountry ) bool needsCountryName = ( format == LabelFormat::AlwaysWithCountry )
|| ( locale.contains( '_' ) && QLocale::countriesForLanguage( m_locale.language() ).count() > 1 ); || ( localeId.name.contains( '_' ) && QLocale::countriesForLanguage( m_locale.language() ).count() > 1 );
QString countryName = ( needsCountryName ? QString countryName = ( needsCountryName ?
m_locale.nativeCountryName() m_locale.nativeCountryName()
@ -80,15 +81,16 @@ Label::Label( const QString& locale, LabelFormat format, QObject* parent )
} }
QLocale QLocale
Label::getLocale( const QString& localeName ) Translation::getLocale( const Id& localeId )
{ {
const QString& localeName = localeId.name;
if ( localeName.isEmpty() ) if ( localeName.isEmpty() )
{ {
return QLocale(); return QLocale();
} }
auto special = specialCase( localeName ); auto [ locale, _ ] = specialCase( localeId );
return special.first ? *special.first : QLocale( localeName ); return locale ? *locale : QLocale( localeName );
} }
} // namespace Locale } // namespace Locale

View File

@ -9,8 +9,8 @@
* *
*/ */
#ifndef LOCALE_LABEL_H #ifndef LOCALE_TRANSLATION_H
#define LOCALE_LABEL_H #define LOCALE_TRANSLATION_H
#include <QLocale> #include <QLocale>
#include <QObject> #include <QObject>
@ -34,7 +34,7 @@ namespace Locale
* - `ca@valencia` is the Catalan dialect spoken in Valencia. * - `ca@valencia` is the Catalan dialect spoken in Valencia.
* There is no Qt code for it. * There is no Qt code for it.
*/ */
class Label : public QObject class Translation : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -46,8 +46,13 @@ public:
IfNeededWithCountry IfNeededWithCountry
}; };
struct Id
{
QString name;
};
/** @brief Empty locale. This uses the system-default locale. */ /** @brief Empty locale. This uses the system-default locale. */
Label( QObject* parent = nullptr ); Translation( QObject* parent = nullptr );
/** @brief Construct from a locale name. /** @brief Construct from a locale name.
* *
@ -55,16 +60,14 @@ public:
* The @p format determines whether the country name is always present * The @p format determines whether the country name is always present
* in the label (human-readable form) or only if needed for disambiguation. * in the label (human-readable form) or only if needed for disambiguation.
*/ */
Label( const QString& localeName, Translation( const Id& localeId, LabelFormat format = LabelFormat::IfNeededWithCountry, QObject* parent = nullptr );
LabelFormat format = LabelFormat::IfNeededWithCountry,
QObject* parent = nullptr );
/** @brief Define a sorting order. /** @brief Define a sorting order.
* *
* Locales are sorted by their id, which means the ISO 2-letter code + country. * Locales are sorted by their id, which means the ISO 2-letter code + country.
*/ */
bool operator<( const Label& other ) const { return m_localeId < other.m_localeId; } bool operator<( const Translation& other ) const { return m_localeId < other.m_localeId; }
/** @brief Is this locale English? /** @brief Is this locale English?
* *
@ -81,8 +84,12 @@ public:
/** @brief Get the Qt locale. */ /** @brief Get the Qt locale. */
QLocale locale() const { return m_locale; } QLocale locale() const { return m_locale; }
QString name() const { return m_locale.name(); } /** @brief Gets the Calamares internal name (code) of the locale.
QString id() const { return m_localeId; } *
* This is a strongly-typed return to avoid it ending up all over
* the place as a QString.
*/
Id id() const { return { m_localeId }; }
/// @brief Convenience accessor to the language part of the locale /// @brief Convenience accessor to the language part of the locale
QLocale::Language language() const { return m_locale.language(); } QLocale::Language language() const { return m_locale.language(); }
@ -94,9 +101,9 @@ public:
* *
* This obeys special cases as described in the class documentation. * This obeys special cases as described in the class documentation.
*/ */
static QLocale getLocale( const QString& localeName ); static QLocale getLocale( const Id& localeId );
protected: private:
QLocale m_locale; QLocale m_locale;
QString m_localeId; // the locale identifier, e.g. "en_GB" QString m_localeId; // the locale identifier, e.g. "en_GB"
QString m_label; // the native name of the locale QString m_label; // the native name of the locale

View File

@ -9,7 +9,7 @@
* *
*/ */
#include "LabelModel.h" #include "TranslationsModel.h"
#include "Lookup.h" #include "Lookup.h"
@ -20,7 +20,7 @@ namespace CalamaresUtils
namespace Locale namespace Locale
{ {
LabelModel::LabelModel( const QStringList& locales, QObject* parent ) TranslationsModel::TranslationsModel( const QStringList& locales, QObject* parent )
: QAbstractListModel( parent ) : QAbstractListModel( parent )
, m_localeIds( locales ) , m_localeIds( locales )
{ {
@ -29,20 +29,20 @@ LabelModel::LabelModel( const QStringList& locales, QObject* parent )
for ( const auto& l : locales ) for ( const auto& l : locales )
{ {
m_locales.push_back( new Label( l, Label::LabelFormat::IfNeededWithCountry, this ) ); m_locales.push_back( new Translation( { l }, Translation::LabelFormat::IfNeededWithCountry, this ) );
} }
} }
LabelModel::~LabelModel() {} TranslationsModel::~TranslationsModel() {}
int int
LabelModel::rowCount( const QModelIndex& ) const TranslationsModel::rowCount( const QModelIndex& ) const
{ {
return m_locales.count(); return m_locales.count();
} }
QVariant QVariant
LabelModel::data( const QModelIndex& index, int role ) const TranslationsModel::data( const QModelIndex& index, int role ) const
{ {
if ( ( role != LabelRole ) && ( role != EnglishLabelRole ) ) if ( ( role != LabelRole ) && ( role != EnglishLabelRole ) )
{ {
@ -67,13 +67,13 @@ LabelModel::data( const QModelIndex& index, int role ) const
} }
QHash< int, QByteArray > QHash< int, QByteArray >
LabelModel::roleNames() const TranslationsModel::roleNames() const
{ {
return { { LabelRole, "label" }, { EnglishLabelRole, "englishLabel" } }; return { { LabelRole, "label" }, { EnglishLabelRole, "englishLabel" } };
} }
const Label& const Translation&
LabelModel::locale( int row ) const TranslationsModel::locale( int row ) const
{ {
if ( ( row < 0 ) || ( row >= m_locales.count() ) ) if ( ( row < 0 ) || ( row >= m_locales.count() ) )
{ {
@ -88,7 +88,7 @@ LabelModel::locale( int row ) const
} }
int int
LabelModel::find( std::function< bool( const Label& ) > predicate ) const TranslationsModel::find( std::function< bool( const Translation& ) > predicate ) const
{ {
for ( int row = 0; row < m_locales.count(); ++row ) for ( int row = 0; row < m_locales.count(); ++row )
{ {
@ -101,19 +101,19 @@ LabelModel::find( std::function< bool( const Label& ) > predicate ) const
} }
int int
LabelModel::find( std::function< bool( const QLocale& ) > predicate ) const TranslationsModel::find( std::function< bool( const QLocale& ) > predicate ) const
{ {
return find( [&]( const Label& l ) { return predicate( l.locale() ); } ); return find( [&]( const Translation& l ) { return predicate( l.locale() ); } );
} }
int int
LabelModel::find( const QLocale& locale ) const TranslationsModel::find( const QLocale& locale ) const
{ {
return find( [&]( const Label& l ) { return locale == l.locale(); } ); return find( [&]( const Translation& l ) { return locale == l.locale(); } );
} }
int int
LabelModel::find( const QString& countryCode ) const TranslationsModel::find( const QString& countryCode ) const
{ {
if ( countryCode.length() != 2 ) if ( countryCode.length() != 2 )
{ {
@ -121,18 +121,20 @@ LabelModel::find( const QString& countryCode ) const
} }
auto c_l = countryData( countryCode ); auto c_l = countryData( countryCode );
int r = find( [&]( const Label& l ) { return ( l.language() == c_l.second ) && ( l.country() == c_l.first ); } ); int r = find(
[&]( const Translation& l ) { return ( l.language() == c_l.second ) && ( l.country() == c_l.first ); } );
if ( r >= 0 ) if ( r >= 0 )
{ {
return r; return r;
} }
return find( [&]( const Label& l ) { return l.language() == c_l.second; } ); return find( [&]( const Translation& l ) { return l.language() == c_l.second; } );
} }
LabelModel* TranslationsModel*
availableTranslations() availableTranslations()
{ {
static LabelModel* model = new LabelModel( QStringLiteral( CALAMARES_TRANSLATION_LANGUAGES ).split( ';' ) ); static TranslationsModel* model
= new TranslationsModel( QStringLiteral( CALAMARES_TRANSLATION_LANGUAGES ).split( ';' ) );
return model; return model;
} }

View File

@ -9,11 +9,11 @@
* *
*/ */
#ifndef LOCALE_LABELMODEL_H #ifndef LOCALE_TRANSLATIONSMODEL_H
#define LOCALE_LABELMODEL_H #define LOCALE_TRANSLATIONSMODEL_H
#include "DllMacro.h" #include "DllMacro.h"
#include "Label.h" #include "Translation.h"
#include <QAbstractListModel> #include <QAbstractListModel>
#include <QVector> #include <QVector>
@ -24,7 +24,7 @@ namespace CalamaresUtils
namespace Locale namespace Locale
{ {
class DLLEXPORT LabelModel : public QAbstractListModel class DLLEXPORT TranslationsModel : public QAbstractListModel
{ {
Q_OBJECT Q_OBJECT
@ -35,8 +35,8 @@ public:
EnglishLabelRole = Qt::UserRole + 1 EnglishLabelRole = Qt::UserRole + 1
}; };
LabelModel( const QStringList& locales, QObject* parent = nullptr ); TranslationsModel( const QStringList& locales, QObject* parent = nullptr );
~LabelModel() override; ~TranslationsModel() override;
int rowCount( const QModelIndex& parent ) const override; int rowCount( const QModelIndex& parent ) const override;
@ -48,7 +48,7 @@ public:
* This is the backing data for the model; if @p row is out-of-range, * This is the backing data for the model; if @p row is out-of-range,
* returns a reference to en_US. * returns a reference to en_US.
*/ */
const Label& locale( int row ) const; const Translation& locale( int row ) const;
/// @brief Returns all of the locale Ids (e.g. en_US) put into this model. /// @brief Returns all of the locale Ids (e.g. en_US) put into this model.
const QStringList& localeIds() const { return m_localeIds; } const QStringList& localeIds() const { return m_localeIds; }
@ -58,14 +58,14 @@ public:
* Returns the row number of the first match, or -1 if there isn't one. * Returns the row number of the first match, or -1 if there isn't one.
*/ */
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 Translation& ) > predicate ) const;
/// @brief Looks for an item using the same locale, -1 if there isn't one /// @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 /// @brief Looks for an item that best matches the 2-letter country code
int find( const QString& countryCode ) const; int find( const QString& countryCode ) const;
private: private:
QVector< Label* > m_locales; QVector< Translation* > m_locales;
QStringList m_localeIds; QStringList m_localeIds;
}; };
@ -79,7 +79,7 @@ private:
* *
* NOTE: While the model is not typed const, it should be. Do not modify. * NOTE: While the model is not typed const, it should be. Do not modify.
*/ */
DLLEXPORT LabelModel* availableTranslations(); DLLEXPORT TranslationsModel* availableTranslations();
} // namespace Locale } // namespace Locale
} // namespace CalamaresUtils } // namespace CalamaresUtils
#endif #endif

View File

@ -19,6 +19,9 @@
#include <QEvent> #include <QEvent>
#include <QTranslator> #include <QTranslator>
namespace
{
static bool s_allowLocalTranslations = false; static bool s_allowLocalTranslations = false;
/** @brief Helper class for loading translations /** @brief Helper class for loading translations
@ -28,29 +31,8 @@ static bool s_allowLocalTranslations = false;
*/ */
struct TranslationLoader struct TranslationLoader
{ {
static QString mungeLocaleName( const QLocale& locale ) TranslationLoader( const QString& locale )
{ : m_localeName( locale )
QString localeName = locale.name();
localeName.replace( "-", "_" );
if ( localeName == "C" )
{
localeName = "en";
}
// Special case of sr@latin
//
// See top-level CMakeLists.txt about special cases for translation loading.
if ( locale.language() == QLocale::Language::Serbian && locale.script() == QLocale::Script::LatinScript )
{
localeName = QStringLiteral( "sr@latin" );
}
return localeName;
}
TranslationLoader( const QLocale& locale )
: m_locale( locale )
, m_localeName( mungeLocaleName( locale ) )
{ {
} }
@ -58,14 +40,13 @@ struct TranslationLoader
/// @brief Loads @p translator with the specific translations of this type /// @brief Loads @p translator with the specific translations of this type
virtual bool tryLoad( QTranslator* translator ) = 0; virtual bool tryLoad( QTranslator* translator ) = 0;
const QLocale& m_locale;
QString m_localeName; QString m_localeName;
}; };
/// @brief Loads translations for branding /// @brief Loads translations for branding
struct BrandingLoader : public TranslationLoader struct BrandingLoader : public TranslationLoader
{ {
BrandingLoader( const QLocale& locale, const QString& prefix ) BrandingLoader( const QString& locale, const QString& prefix )
: TranslationLoader( locale ) : TranslationLoader( locale )
, m_prefix( prefix ) , m_prefix( prefix )
{ {
@ -106,7 +87,7 @@ BrandingLoader::tryLoad( QTranslator* translator )
{ {
QString filenameBase( m_prefix ); QString filenameBase( m_prefix );
filenameBase.remove( 0, m_prefix.lastIndexOf( QDir::separator() ) + 1 ); filenameBase.remove( 0, m_prefix.lastIndexOf( QDir::separator() ) + 1 );
if ( translator->load( m_locale, filenameBase, "_", brandingTranslationsDir.absolutePath() ) ) if ( translator->load( m_localeName, filenameBase, "_", brandingTranslationsDir.absolutePath() ) )
{ {
cDebug() << Logger::SubEntry << "Branding using locale:" << m_localeName; cDebug() << Logger::SubEntry << "Branding using locale:" << m_localeName;
return true; return true;
@ -181,6 +162,8 @@ loadSingletonTranslator( TranslationLoader&& loader, QTranslator*& translator_p
} }
} }
} // namespace
namespace CalamaresUtils namespace CalamaresUtils
{ {
static QTranslator* s_brandingTranslator = nullptr; static QTranslator* s_brandingTranslator = nullptr;
@ -189,26 +172,32 @@ static QTranslator* s_tztranslator = nullptr;
static QString s_translatorLocaleName; static QString s_translatorLocaleName;
void void
installTranslator( const QLocale& locale, const QString& brandingTranslationsPrefix ) installTranslator( const CalamaresUtils::Locale::Translation::Id& locale, const QString& brandingTranslationsPrefix )
{ {
loadSingletonTranslator( BrandingLoader( locale, brandingTranslationsPrefix ), s_brandingTranslator ); s_translatorLocaleName = locale.name;
loadSingletonTranslator( TZLoader( locale ), s_tztranslator );
loadSingletonTranslator( CalamaresLoader( locale ), s_translator );
s_translatorLocaleName = CalamaresLoader::mungeLocaleName( locale ); loadSingletonTranslator( BrandingLoader( locale.name, brandingTranslationsPrefix ), s_brandingTranslator );
loadSingletonTranslator( TZLoader( locale.name ), s_tztranslator );
loadSingletonTranslator( CalamaresLoader( locale.name ), s_translator );
} }
void
installTranslator()
{
// Just wrap it up like an Id
installTranslator( { QLocale::system().name() }, QString() );
}
QString CalamaresUtils::Locale::Translation::Id
translatorLocaleName() translatorLocaleName()
{ {
return s_translatorLocaleName; return { s_translatorLocaleName };
} }
bool bool
loadTranslator( const QLocale& locale, const QString& prefix, QTranslator* translator ) loadTranslator( const CalamaresUtils::Locale::Translation::Id& locale, const QString& prefix, QTranslator* translator )
{ {
return ::tryLoad( translator, prefix, locale.name() ); return ::tryLoad( translator, prefix, locale.name );
} }
Retranslator::Retranslator( QObject* parent ) Retranslator::Retranslator( QObject* parent )
@ -227,13 +216,15 @@ Retranslator::eventFilter( QObject* obj, QEvent* e )
return QObject::eventFilter( obj, e ); return QObject::eventFilter( obj, e );
} }
Retranslator* Retranslator::instance() Retranslator*
Retranslator::instance()
{ {
static Retranslator s_instance(nullptr); static Retranslator s_instance( nullptr );
return &s_instance; return &s_instance;
} }
void Retranslator::attach(QObject* o, std::function<void ()> f) void
Retranslator::attach( QObject* o, std::function< void() > f )
{ {
connect( instance(), &Retranslator::languageChanged, o, f ); connect( instance(), &Retranslator::languageChanged, o, f );
f(); f();

View File

@ -12,8 +12,8 @@
#define UTILS_RETRANSLATOR_H #define UTILS_RETRANSLATOR_H
#include "DllMacro.h" #include "DllMacro.h"
#include "locale/Translation.h"
#include <QList>
#include <QObject> #include <QObject>
#include <QString> #include <QString>
@ -25,12 +25,15 @@ class QTranslator;
namespace CalamaresUtils namespace CalamaresUtils
{ {
/** /** @brief changes the application language.
* @brief installTranslator changes the application language. * @param locale the new locale (names as defined by Calamares).
* @param locale the new locale.
* @param brandingTranslationsPrefix the branding path prefix, from Calamares::Branding. * @param brandingTranslationsPrefix the branding path prefix, from Calamares::Branding.
*/ */
DLLEXPORT void installTranslator( const QLocale& locale, const QString& brandingTranslationsPrefix ); DLLEXPORT void installTranslator( const CalamaresUtils::Locale::Translation::Id& locale, const QString& brandingTranslationsPrefix );
/** @brief Initializes the translations with the current system settings
*/
DLLEXPORT void installTranslator();
/** @brief The name of the (locale of the) most recently installed translator /** @brief The name of the (locale of the) most recently installed translator
* *
@ -38,7 +41,7 @@ DLLEXPORT void installTranslator( const QLocale& locale, const QString& branding
* QLocale passed in, because Calamares will munge some names and * QLocale passed in, because Calamares will munge some names and
* may remap translations. * may remap translations.
*/ */
DLLEXPORT QString translatorLocaleName(); DLLEXPORT CalamaresUtils::Locale::Translation::Id translatorLocaleName();
/** @brief Loads <prefix><locale> translations into the given @p translator /** @brief Loads <prefix><locale> translations into the given @p translator
* *
@ -53,7 +56,7 @@ DLLEXPORT QString translatorLocaleName();
* *
* @returns @c true on success * @returns @c true on success
*/ */
DLLEXPORT bool loadTranslator( const QLocale& locale, const QString& prefix, QTranslator* translator ); DLLEXPORT bool loadTranslator( const CalamaresUtils::Locale::Translation::Id& locale, const QString& prefix, QTranslator* translator );
/** @brief Set @p allow to true to load translations from current dir. /** @brief Set @p allow to true to load translations from current dir.
* *

View File

@ -27,7 +27,7 @@ retranslateKeyboardModels()
{ {
s_kbtranslator = new QTranslator; s_kbtranslator = new QTranslator;
} }
(void)CalamaresUtils::loadTranslator( QLocale(), QStringLiteral( "kb_" ), s_kbtranslator ); (void)CalamaresUtils::loadTranslator( CalamaresUtils::translatorLocaleName(), QStringLiteral( "kb_" ), s_kbtranslator );
} }

View File

@ -15,7 +15,7 @@
#include "JobQueue.h" #include "JobQueue.h"
#include "Settings.h" #include "Settings.h"
#include "locale/Global.h" #include "locale/Global.h"
#include "locale/Label.h" #include "locale/Translation.h"
#include "modulesystem/ModuleManager.h" #include "modulesystem/ModuleManager.h"
#include "network/Manager.h" #include "network/Manager.h"
#include "utils/Logger.h" #include "utils/Logger.h"
@ -368,9 +368,9 @@ Config::currentTimezoneName() const
static inline QString static inline QString
localeLabel( const QString& s ) localeLabel( const QString& s )
{ {
using CalamaresUtils::Locale::Label; using CalamaresUtils::Locale::Translation;
Label lang( s, Label::LabelFormat::AlwaysWithCountry ); Translation lang( { s }, Translation::LabelFormat::AlwaysWithCountry );
return lang.label(); return lang.label();
} }

View File

@ -85,7 +85,7 @@ Config::retranslate()
emit warningMessageChanged( m_warningMessage ); emit warningMessageChanged( m_warningMessage );
} }
CalamaresUtils::Locale::LabelModel* CalamaresUtils::Locale::TranslationsModel*
Config::languagesModel() const Config::languagesModel() const
{ {
return m_languages; return m_languages;
@ -152,8 +152,6 @@ Config::initLanguages()
if ( matchedLocaleIndex >= 0 ) if ( matchedLocaleIndex >= 0 )
{ {
QString name = m_languages->locale( matchedLocaleIndex ).name();
cDebug() << Logger::SubEntry << "Matched with index" << matchedLocaleIndex << name;
setLocaleIndex( matchedLocaleIndex ); setLocaleIndex( matchedLocaleIndex );
} }
else else
@ -188,17 +186,17 @@ Config::setLocaleIndex( int index )
m_localeIndex = index; m_localeIndex = index;
const auto& selectedLocale = m_languages->locale( m_localeIndex ).locale(); const auto& selectedTranslation = m_languages->locale( m_localeIndex );
cDebug() << "Index" << index << "Selected locale" << selectedLocale; cDebug() << "Index" << index << "Selected locale" << selectedTranslation.id().name;
QLocale::setDefault( selectedLocale ); QLocale::setDefault( selectedTranslation.locale() );
const auto* branding = Calamares::Branding::instance(); const auto* branding = Calamares::Branding::instance();
CalamaresUtils::installTranslator( selectedLocale, branding ? branding->translationsDirectory() : QString() ); CalamaresUtils::installTranslator( selectedTranslation.id(), branding ? branding->translationsDirectory() : QString() );
if ( Calamares::JobQueue::instance() && Calamares::JobQueue::instance()->globalStorage() ) if ( Calamares::JobQueue::instance() && Calamares::JobQueue::instance()->globalStorage() )
{ {
CalamaresUtils::Locale::insertGS( *Calamares::JobQueue::instance()->globalStorage(), CalamaresUtils::Locale::insertGS( *Calamares::JobQueue::instance()->globalStorage(),
QStringLiteral( "LANG" ), QStringLiteral( "LANG" ),
CalamaresUtils::translatorLocaleName() ); CalamaresUtils::translatorLocaleName().name );
} }
emit localeIndexChanged( m_localeIndex ); emit localeIndexChanged( m_localeIndex );
} }

View File

@ -11,8 +11,7 @@
#define WELCOME_CONFIG_H #define WELCOME_CONFIG_H
#include "checker/GeneralRequirements.h" #include "checker/GeneralRequirements.h"
#include "locale/TranslationsModel.h"
#include "locale/LabelModel.h"
#include "modulesystem/RequirementsModel.h" #include "modulesystem/RequirementsModel.h"
#include <QObject> #include <QObject>
@ -29,7 +28,7 @@ class Config : public QObject
* This is a list-model, with names and descriptions for the translations * This is a list-model, with names and descriptions for the translations
* available to Calamares. * available to Calamares.
*/ */
Q_PROPERTY( CalamaresUtils::Locale::LabelModel* languagesModel READ languagesModel CONSTANT FINAL ) Q_PROPERTY( CalamaresUtils::Locale::TranslationsModel* languagesModel READ languagesModel CONSTANT FINAL )
/** @brief The requirements (from modules) and their checked-status /** @brief The requirements (from modules) and their checked-status
* *
* The model grows rows over time as each module is checked and its * The model grows rows over time as each module is checked and its
@ -94,7 +93,7 @@ public:
QString warningMessage() const; QString warningMessage() const;
public slots: public slots:
CalamaresUtils::Locale::LabelModel* languagesModel() const; CalamaresUtils::Locale::TranslationsModel* languagesModel() const;
void retranslate(); void retranslate();
///@brief The **global** requirements model, from ModuleManager ///@brief The **global** requirements model, from ModuleManager
@ -121,7 +120,7 @@ signals:
private: private:
void initLanguages(); void initLanguages();
CalamaresUtils::Locale::LabelModel* m_languages = nullptr; CalamaresUtils::Locale::TranslationsModel* m_languages = nullptr;
std::unique_ptr< QSortFilterProxyModel > m_filtermodel; std::unique_ptr< QSortFilterProxyModel > m_filtermodel;
std::unique_ptr< GeneralRequirements > m_requirementsChecker; std::unique_ptr< GeneralRequirements > m_requirementsChecker;

View File

@ -20,7 +20,6 @@
#include "Settings.h" #include "Settings.h"
#include "ViewManager.h" #include "ViewManager.h"
#include "locale/LabelModel.h"
#include "modulesystem/ModuleManager.h" #include "modulesystem/ModuleManager.h"
#include "modulesystem/RequirementsModel.h" #include "modulesystem/RequirementsModel.h"
#include "utils/CalamaresUtilsGui.h" #include "utils/CalamaresUtilsGui.h"
@ -275,5 +274,5 @@ LocaleTwoColumnDelegate::paint( QPainter* painter, const QStyleOptionViewItem& o
Qt::AlignRight | Qt::AlignVCenter, Qt::AlignRight | Qt::AlignVCenter,
option.palette, option.palette,
false, false,
index.data( CalamaresUtils::Locale::LabelModel::EnglishLabelRole ).toString() ); index.data( CalamaresUtils::Locale::TranslationsModel::EnglishLabelRole ).toString() );
} }

View File

@ -11,7 +11,7 @@
#ifndef WELCOMEPAGE_H #ifndef WELCOMEPAGE_H
#define WELCOMEPAGE_H #define WELCOMEPAGE_H
#include "locale/LabelModel.h" #include "locale/TranslationsModel.h"
#include <QStyledItemDelegate> #include <QStyledItemDelegate>
#include <QWidget> #include <QWidget>
@ -64,7 +64,7 @@ private:
Ui::WelcomePage* ui; Ui::WelcomePage* ui;
CheckerContainer* m_checkingWidget; CheckerContainer* m_checkingWidget;
CalamaresUtils::Locale::LabelModel* m_languages; CalamaresUtils::Locale::TranslationsModel* m_languages;
Config* m_conf; Config* m_conf;
}; };

View File

@ -12,7 +12,7 @@
#include "checker/GeneralRequirements.h" #include "checker/GeneralRequirements.h"
#include "locale/LabelModel.h" #include "locale/TranslationsModel.h"
#include "utils/Dirs.h" #include "utils/Dirs.h"
#include "utils/Logger.h" #include "utils/Logger.h"
#include "utils/Variant.h" #include "utils/Variant.h"