diff --git a/CMakeModules/ExtendedVersion.cmake b/CMakeModules/ExtendedVersion.cmake index b737dd2e2..87bf892e1 100644 --- a/CMakeModules/ExtendedVersion.cmake +++ b/CMakeModules/ExtendedVersion.cmake @@ -57,11 +57,6 @@ function( extend_version version short_only short_var long_var ) set( ${short_var} "${version}" PARENT_SCOPE ) set( _v "${version}" ) if ( NOT short_only ) - # Additional info for non-release builds which want "long" version info - # with date and git information (commit, dirty status). That is used only - # by CalamaresVersionX.h, which is included by consumers that need a full - # version number with all that information; normal consumers can include - # CalamaresVersion.h with more stable numbers. string( TIMESTAMP CALAMARES_VERSION_DATE "%Y%m%d" ) if( CALAMARES_VERSION_DATE GREATER 0 ) set( _v ${_v}.${CALAMARES_VERSION_DATE} ) diff --git a/src/calamares/CalamaresApplication.cpp b/src/calamares/CalamaresApplication.cpp index c06e13aa3..88e8e2919 100644 --- a/src/calamares/CalamaresApplication.cpp +++ b/src/calamares/CalamaresApplication.cpp @@ -18,6 +18,7 @@ #include "JobQueue.h" #include "Settings.h" #include "ViewManager.h" +#include "locale/TranslationsModel.h" #include "modulesystem/ModuleManager.h" #include "utils/CalamaresUtilsGui.h" #include "utils/CalamaresUtilsSystem.h" @@ -67,7 +68,7 @@ CalamaresApplication::init() { Logger::setupLogfile(); cDebug() << "Calamares version:" << CALAMARES_VERSION; - cDebug() << Logger::SubEntry << "languages:" << QString( CALAMARES_TRANSLATION_LANGUAGES ).replace( ";", ", " ); + cDebug() << Logger::SubEntry << "languages:" << Calamares::Locale::availableLanguages(); if ( !Calamares::Settings::instance() ) { diff --git a/src/libcalamares/CMakeLists.txt b/src/libcalamares/CMakeLists.txt index 181ec2b30..2a0738ec0 100644 --- a/src/libcalamares/CMakeLists.txt +++ b/src/libcalamares/CMakeLists.txt @@ -17,6 +17,21 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CalamaresConfig.h.in ${CMAKE_CURRENT_ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CalamaresVersion.h.in ${CMAKE_CURRENT_BINARY_DIR}/CalamaresVersion.h) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CalamaresVersionX.h.in ${CMAKE_CURRENT_BINARY_DIR}/CalamaresVersionX.h) +# Map the available translations names into a suitable constexpr list +# of names in C++. This gets us Calamares::Locale::availableLanguages, +# a QStringList of names. +set(_names_tu "#ifndef CALAMARES_TRANSLATIONS_H +#define CALAMARES_TRANSLATIONS_H +#include +namespace { +static const QStringList availableLanguageList{ +") +foreach( l ${CALAMARES_TRANSLATION_LANGUAGES}) + string(APPEND _names_tu "\"${l}\",\n") +endforeach() +string(APPEND _names_tu "};\n} // namespace\n#endif\n\n") +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/CalamaresTranslations.cc "${_names_tu}") + add_library( calamares SHARED diff --git a/src/libcalamares/CalamaresVersion.h.in b/src/libcalamares/CalamaresVersion.h.in index 09ef9ae2c..5a83d467f 100644 --- a/src/libcalamares/CalamaresVersion.h.in +++ b/src/libcalamares/CalamaresVersion.h.in @@ -14,6 +14,4 @@ #cmakedefine CALAMARES_VERSION_PATCH "${CALAMARES_VERSION_PATCH}" #cmakedefine CALAMARES_VERSION_RC "${CALAMARES_VERSION_RC}" -#cmakedefine CALAMARES_TRANSLATION_LANGUAGES "${CALAMARES_TRANSLATION_LANGUAGES}" - #endif // CALAMARES_VERSION_H diff --git a/src/libcalamares/locale/Lookup.cpp b/src/libcalamares/locale/Lookup.cpp index 3dba50898..60c36fdf6 100644 --- a/src/libcalamares/locale/Lookup.cpp +++ b/src/libcalamares/locale/Lookup.cpp @@ -12,7 +12,7 @@ #include "CountryData_p.cpp" -namespace CalamaresUtils +namespace Calamares { namespace Locale { @@ -95,4 +95,4 @@ languageForCountry( QLocale::Country country ) } } // namespace Locale -} // namespace CalamaresUtils +} // namespace Calamares diff --git a/src/libcalamares/locale/Lookup.h b/src/libcalamares/locale/Lookup.h index 4095fd097..d026f9343 100644 --- a/src/libcalamares/locale/Lookup.h +++ b/src/libcalamares/locale/Lookup.h @@ -16,7 +16,7 @@ #include #include -namespace CalamaresUtils +namespace Calamares { namespace Locale { @@ -42,6 +42,6 @@ DLLEXPORT QPair< QLocale::Country, QLocale::Language > countryData( const QStrin /// @brief Get a likely locale for a 2-letter country code DLLEXPORT QLocale countryLocale( const QString& code ); } // namespace Locale -} // namespace CalamaresUtils +} // namespace Calamares #endif diff --git a/src/libcalamares/locale/Tests.cpp b/src/libcalamares/locale/Tests.cpp index f234c1596..80ae195c6 100644 --- a/src/libcalamares/locale/Tests.cpp +++ b/src/libcalamares/locale/Tests.cpp @@ -71,7 +71,7 @@ LocaleTests::initTestCase() void LocaleTests::testLanguageModelCount() { - const auto* m = CalamaresUtils::Locale::availableTranslations(); + const auto* m = Calamares::Locale::availableTranslations(); QVERIFY( m ); QVERIFY( m->rowCount( QModelIndex() ) > 1 ); @@ -90,7 +90,7 @@ LocaleTests::testLanguageModelCount() void LocaleTests::testLanguageScripts() { - const auto* m = CalamaresUtils::Locale::availableTranslations(); + const auto* m = Calamares::Locale::availableTranslations(); QVERIFY( m ); @@ -153,12 +153,11 @@ someLanguages() void LocaleTests::testTranslatableLanguages() { - QStringList availableLanguages = QString( CALAMARES_TRANSLATION_LANGUAGES ).split( ';' ); - cDebug() << "Translation languages:" << availableLanguages; + cDebug() << "Translation languages:" << Calamares::Locale::availableLanguages(); for ( const auto& language : someLanguages() ) { // Could be QVERIFY, but then we don't see what language code fails - QCOMPARE( availableLanguages.contains( language ) ? language : QString(), language ); + QCOMPARE( Calamares::Locale::availableLanguages().contains( language ) ? language : QString(), language ); } } diff --git a/src/libcalamares/locale/Translation.cpp b/src/libcalamares/locale/Translation.cpp index 279949d3f..9d2beafb8 100644 --- a/src/libcalamares/locale/Translation.cpp +++ b/src/libcalamares/locale/Translation.cpp @@ -128,7 +128,7 @@ specialCaseSystemLanguage() return ( it != std::cend( special_cases ) ) ? QString::fromLatin1( it->id ) : QString(); } -namespace CalamaresUtils +namespace Calamares { namespace Locale { @@ -187,4 +187,4 @@ Translation::getLocale( const Id& localeId ) } } // namespace Locale -} // namespace CalamaresUtils +} // namespace Calamares diff --git a/src/libcalamares/locale/Translation.h b/src/libcalamares/locale/Translation.h index 912a509ac..e7f066475 100644 --- a/src/libcalamares/locale/Translation.h +++ b/src/libcalamares/locale/Translation.h @@ -18,7 +18,7 @@ #include #include -namespace CalamaresUtils +namespace Calamares { namespace Locale { @@ -124,6 +124,6 @@ operator==( const Translation::Id& lhs, const Translation::Id& rhs ) } } // namespace Locale -} // namespace CalamaresUtils +} // namespace Calamares #endif diff --git a/src/libcalamares/locale/TranslationsModel.cpp b/src/libcalamares/locale/TranslationsModel.cpp index 0ffa6f9c5..a222a02d4 100644 --- a/src/libcalamares/locale/TranslationsModel.cpp +++ b/src/libcalamares/locale/TranslationsModel.cpp @@ -13,9 +13,9 @@ #include "Lookup.h" -#include "CalamaresVersion.h" // For the list of translations +#include "CalamaresTranslations.cc" // For the list of translations, generated at build time -namespace CalamaresUtils +namespace Calamares { namespace Locale { @@ -139,10 +139,15 @@ TranslationsModel::find( const Translation::Id& id ) const TranslationsModel* availableTranslations() { - static TranslationsModel* model - = new TranslationsModel( QStringLiteral( CALAMARES_TRANSLATION_LANGUAGES ).split( ';' ) ); + static TranslationsModel* model = new TranslationsModel( availableLanguageList ); return model; } +const QStringList& +availableLanguages() +{ + return availableLanguageList; +} + } // namespace Locale -} // namespace CalamaresUtils +} // namespace Calamares diff --git a/src/libcalamares/locale/TranslationsModel.h b/src/libcalamares/locale/TranslationsModel.h index 3cd7c61dc..c755f6dca 100644 --- a/src/libcalamares/locale/TranslationsModel.h +++ b/src/libcalamares/locale/TranslationsModel.h @@ -19,7 +19,7 @@ #include -namespace CalamaresUtils +namespace Calamares { namespace Locale { @@ -74,14 +74,22 @@ private: /** @brief Returns a model with all available translations. * * The translations are set when Calamares is compiled; the list - * is provided by CMake via the CALAMARES_TRANSLATION_LANGUAGES - * #define. + * of names used can be queried with avalableLanguages(). * * This model is a singleton and can be shared. * * NOTE: While the model is not typed const, it should be. Do not modify. */ DLLEXPORT TranslationsModel* availableTranslations(); + +/** @brief The list of names (e.g. en, pt_BR) of available translations. + * + * The translations are set when Calamares is compiled. + * At CMake-time, the list CALAMARES_TRANSLATION_LANGUAGES + * is used to create the table. + */ +DLLEXPORT const QStringList& availableLanguages(); + } // namespace Locale -} // namespace CalamaresUtils +} // namespace Calamares #endif diff --git a/src/libcalamares/utils/Retranslator.cpp b/src/libcalamares/utils/Retranslator.cpp index f3ae93836..5af975002 100644 --- a/src/libcalamares/utils/Retranslator.cpp +++ b/src/libcalamares/utils/Retranslator.cpp @@ -178,7 +178,7 @@ static QTranslator* s_tztranslator = nullptr; static QString s_translatorLocaleName; void -installTranslator( const CalamaresUtils::Locale::Translation::Id& locale, const QString& brandingTranslationsPrefix ) +installTranslator( const Calamares::Locale::Translation::Id& locale, const QString& brandingTranslationsPrefix ) { s_translatorLocaleName = locale.name; @@ -190,17 +190,17 @@ installTranslator( const CalamaresUtils::Locale::Translation::Id& locale, const void installTranslator() { - installTranslator( CalamaresUtils::Locale::Translation().id(), QString() ); + installTranslator( Calamares::Locale::Translation().id(), QString() ); } -CalamaresUtils::Locale::Translation::Id +Calamares::Locale::Translation::Id translatorLocaleName() { return { s_translatorLocaleName }; } bool -loadTranslator( const CalamaresUtils::Locale::Translation::Id& locale, const QString& prefix, QTranslator* translator ) +loadTranslator( const Calamares::Locale::Translation::Id& locale, const QString& prefix, QTranslator* translator ) { return ::tryLoad( translator, prefix, locale.name ); } diff --git a/src/libcalamares/utils/Retranslator.h b/src/libcalamares/utils/Retranslator.h index 94eba8b1c..33106d4c8 100644 --- a/src/libcalamares/utils/Retranslator.h +++ b/src/libcalamares/utils/Retranslator.h @@ -29,7 +29,7 @@ namespace CalamaresUtils * @param locale the new locale (names as defined by Calamares). * @param brandingTranslationsPrefix the branding path prefix, from Calamares::Branding. */ -DLLEXPORT void installTranslator( const CalamaresUtils::Locale::Translation::Id& locale, +DLLEXPORT void installTranslator( const Calamares::Locale::Translation::Id& locale, const QString& brandingTranslationsPrefix ); /** @brief Initializes the translations with the current system settings @@ -42,7 +42,7 @@ DLLEXPORT void installTranslator(); * QLocale passed in, because Calamares will munge some names and * may remap translations. */ -DLLEXPORT CalamaresUtils::Locale::Translation::Id translatorLocaleName(); +DLLEXPORT Calamares::Locale::Translation::Id translatorLocaleName(); /** @brief Loads translations into the given @p translator * @@ -58,7 +58,7 @@ DLLEXPORT CalamaresUtils::Locale::Translation::Id translatorLocaleName(); * @returns @c true on success */ DLLEXPORT bool -loadTranslator( const CalamaresUtils::Locale::Translation::Id& locale, const QString& prefix, QTranslator* translator ); +loadTranslator( const Calamares::Locale::Translation::Id& locale, const QString& prefix, QTranslator* translator ); /** @brief Set @p allow to true to load translations from current dir. * diff --git a/src/modules/locale/Config.cpp b/src/modules/locale/Config.cpp index 2357019a7..8167aaec2 100644 --- a/src/modules/locale/Config.cpp +++ b/src/modules/locale/Config.cpp @@ -399,7 +399,7 @@ Config::currentTimezoneName() const static inline QString localeLabel( const QString& s ) { - using CalamaresUtils::Locale::Translation; + using Calamares::Locale::Translation; Translation lang( { s }, Translation::LabelFormat::AlwaysWithCountry ); return lang.label(); diff --git a/src/modules/welcome/Config.cpp b/src/modules/welcome/Config.cpp index 0e692637b..ca907d384 100644 --- a/src/modules/welcome/Config.cpp +++ b/src/modules/welcome/Config.cpp @@ -26,7 +26,7 @@ Config::Config( QObject* parent ) : QObject( parent ) - , m_languages( CalamaresUtils::Locale::availableTranslations() ) + , m_languages( Calamares::Locale::availableTranslations() ) , m_filtermodel( std::make_unique< QSortFilterProxyModel >() ) , m_requirementsChecker( std::make_unique< GeneralRequirements >( this ) ) { @@ -84,7 +84,7 @@ Config::retranslate() emit warningMessageChanged( m_warningMessage ); } -CalamaresUtils::Locale::TranslationsModel* +Calamares::Locale::TranslationsModel* Config::languagesModel() const { return m_languages; @@ -120,7 +120,7 @@ void Config::initLanguages() { // Find the best initial translation - CalamaresUtils::Locale::Translation defaultTranslation; + Calamares::Locale::Translation defaultTranslation; cDebug() << "Trying to match locale" << defaultTranslation.id(); int matchedLocaleIndex = m_languages->find( defaultTranslation.id() ); @@ -172,7 +172,7 @@ void Config::setCountryCode( const QString& countryCode ) { m_countryCode = countryCode; - setLocaleIndex( CalamaresUtils::Locale::availableTranslations()->find( m_countryCode ) ); + setLocaleIndex( Calamares::Locale::availableTranslations()->find( m_countryCode ) ); emit countryCodeChanged( m_countryCode ); } @@ -186,7 +186,7 @@ Config::setLanguageIcon( const QString& languageIcon ) void Config::setLocaleIndex( int index ) { - if ( index == m_localeIndex || index > CalamaresUtils::Locale::availableTranslations()->rowCount( QModelIndex() ) + if ( index == m_localeIndex || index > Calamares::Locale::availableTranslations()->rowCount( QModelIndex() ) || index < 0 ) { return; @@ -347,7 +347,7 @@ setCountry( Config* config, const QString& countryCode, CalamaresUtils::GeoIP::H return; } - auto c_l = CalamaresUtils::Locale::countryData( countryCode ); + auto c_l = Calamares::Locale::countryData( countryCode ); if ( c_l.first == QLocale::Country::AnyCountry ) { cDebug() << "Unusable country code" << countryCode; @@ -356,7 +356,7 @@ setCountry( Config* config, const QString& countryCode, CalamaresUtils::GeoIP::H } else { - int r = CalamaresUtils::Locale::availableTranslations()->find( countryCode ); + int r = Calamares::Locale::availableTranslations()->find( countryCode ); if ( r < 0 ) { cDebug() << "Unusable country code" << countryCode << "(no suitable translation)"; diff --git a/src/modules/welcome/Config.h b/src/modules/welcome/Config.h index 49d9a1b11..276f0cc33 100644 --- a/src/modules/welcome/Config.h +++ b/src/modules/welcome/Config.h @@ -28,7 +28,7 @@ class Config : public QObject * This is a list-model, with names and descriptions for the translations * available to Calamares. */ - Q_PROPERTY( CalamaresUtils::Locale::TranslationsModel* languagesModel READ languagesModel CONSTANT FINAL ) + Q_PROPERTY( Calamares::Locale::TranslationsModel* languagesModel READ languagesModel CONSTANT FINAL ) /** @brief The requirements (from modules) and their checked-status * * The model grows rows over time as each module is checked and its @@ -95,7 +95,7 @@ public: QString warningMessage() const; public slots: - CalamaresUtils::Locale::TranslationsModel* languagesModel() const; + Calamares::Locale::TranslationsModel* languagesModel() const; void retranslate(); ///@brief The **global** requirements model, from ModuleManager @@ -122,7 +122,7 @@ signals: private: void initLanguages(); - CalamaresUtils::Locale::TranslationsModel* m_languages = nullptr; + Calamares::Locale::TranslationsModel* m_languages = nullptr; std::unique_ptr< QSortFilterProxyModel > m_filtermodel; std::unique_ptr< GeneralRequirements > m_requirementsChecker; diff --git a/src/modules/welcome/WelcomePage.cpp b/src/modules/welcome/WelcomePage.cpp index 597317069..96675261b 100644 --- a/src/modules/welcome/WelcomePage.cpp +++ b/src/modules/welcome/WelcomePage.cpp @@ -222,5 +222,5 @@ LocaleTwoColumnDelegate::paint( QPainter* painter, const QStyleOptionViewItem& o Qt::AlignRight | Qt::AlignVCenter, option.palette, false, - index.data( CalamaresUtils::Locale::TranslationsModel::EnglishLabelRole ).toString() ); + index.data( Calamares::Locale::TranslationsModel::EnglishLabelRole ).toString() ); } diff --git a/src/modules/welcome/WelcomePage.h b/src/modules/welcome/WelcomePage.h index 71aebd468..163d13eb1 100644 --- a/src/modules/welcome/WelcomePage.h +++ b/src/modules/welcome/WelcomePage.h @@ -63,7 +63,7 @@ private: Ui::WelcomePage* ui; CheckerContainer* m_checkingWidget; - CalamaresUtils::Locale::TranslationsModel* m_languages; + Calamares::Locale::TranslationsModel* m_languages; Config* m_conf; };