[libcalamares] Factor out the list of translations
The list of translation codes lives in one place, make it accessible through a function in Calamares::Locale.
This commit is contained in:
parent
18a3092aa1
commit
170a5a8697
@ -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() )
|
||||
{
|
||||
|
@ -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 <QStringList>
|
||||
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
|
||||
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user