diff --git a/src/calamares/CalamaresApplication.cpp b/src/calamares/CalamaresApplication.cpp index 979ee8cfe..88e8e2919 100644 --- a/src/calamares/CalamaresApplication.cpp +++ b/src/calamares/CalamaresApplication.cpp @@ -10,7 +10,6 @@ #include "CalamaresApplication.h" #include "CalamaresConfig.h" -#include "CalamaresTranslations.h" #include "CalamaresVersionX.h" #include "CalamaresWindow.h" #include "progresstree/ProgressTreeView.h" @@ -19,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" @@ -68,7 +68,7 @@ CalamaresApplication::init() { Logger::setupLogfile(); cDebug() << "Calamares version:" << CALAMARES_VERSION; - cDebug() << Logger::SubEntry << "languages:" << Calamares::Locale::availableLanguages; + cDebug() << Logger::SubEntry << "languages:" << Calamares::Locale::availableLanguages(); if ( !Calamares::Settings::instance() ) { diff --git a/src/libcalamares/CMakeLists.txt b/src/libcalamares/CMakeLists.txt index 0a8b0b570..2a0738ec0 100644 --- a/src/libcalamares/CMakeLists.txt +++ b/src/libcalamares/CMakeLists.txt @@ -23,15 +23,14 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CalamaresVersionX.h.in ${CMAKE_CURREN set(_names_tu "#ifndef CALAMARES_TRANSLATIONS_H #define CALAMARES_TRANSLATIONS_H #include -namespace Calamares { -namespace Locale { -static const QStringList availableLanguages{ +namespace { +static const QStringList availableLanguageList{ ") foreach( l ${CALAMARES_TRANSLATION_LANGUAGES}) string(APPEND _names_tu "\"${l}\",\n") endforeach() -string(APPEND _names_tu "};\n}} // namespaces\n#endif\n\n") -file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/CalamaresTranslations.h "${_names_tu}") +string(APPEND _names_tu "};\n} // namespace\n#endif\n\n") +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/CalamaresTranslations.cc "${_names_tu}") add_library( calamares diff --git a/src/libcalamares/locale/Tests.cpp b/src/libcalamares/locale/Tests.cpp index d32d8fafb..80ae195c6 100644 --- a/src/libcalamares/locale/Tests.cpp +++ b/src/libcalamares/locale/Tests.cpp @@ -13,7 +13,6 @@ #include "locale/TranslatableConfiguration.h" #include "locale/TranslationsModel.h" -#include "CalamaresTranslations.h" #include "CalamaresVersion.h" #include "GlobalStorage.h" #include "utils/Logger.h" @@ -154,11 +153,11 @@ someLanguages() void LocaleTests::testTranslatableLanguages() { - cDebug() << "Translation languages:" << Calamares::Locale::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( Calamares::Locale::availableLanguages.contains( language ) ? language : QString(), language ); + QCOMPARE( Calamares::Locale::availableLanguages().contains( language ) ? language : QString(), language ); } } diff --git a/src/libcalamares/locale/TranslationsModel.cpp b/src/libcalamares/locale/TranslationsModel.cpp index 304246053..a222a02d4 100644 --- a/src/libcalamares/locale/TranslationsModel.cpp +++ b/src/libcalamares/locale/TranslationsModel.cpp @@ -13,7 +13,7 @@ #include "Lookup.h" -#include "CalamaresTranslations.h" // For the list of translations +#include "CalamaresTranslations.cc" // For the list of translations, generated at build time namespace Calamares { @@ -139,9 +139,15 @@ TranslationsModel::find( const Translation::Id& id ) const TranslationsModel* availableTranslations() { - static TranslationsModel* model = new TranslationsModel( Calamares::Locale::availableLanguages ); + static TranslationsModel* model = new TranslationsModel( availableLanguageList ); return model; } +const QStringList& +availableLanguages() +{ + return availableLanguageList; +} + } // namespace Locale } // namespace Calamares diff --git a/src/libcalamares/locale/TranslationsModel.h b/src/libcalamares/locale/TranslationsModel.h index 6982f871f..c755f6dca 100644 --- a/src/libcalamares/locale/TranslationsModel.h +++ b/src/libcalamares/locale/TranslationsModel.h @@ -74,16 +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 - * CMake variable (top-level CMakeLists.txt in Calamares) and - * compiled into the CalamaresTranslations.h internal header. - * #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 Calamares #endif