Merge pull request #2009 from calamares/issue-1940

[libcalamares] Remove translation-languages define
This commit is contained in:
Adriaan de Groot 2022-07-18 23:03:22 +02:00 committed by GitHub
commit 10da2c257d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 71 additions and 50 deletions

View File

@ -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} )

View File

@ -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() )
{

View File

@ -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 <QStringList>
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

View File

@ -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

View File

@ -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

View File

@ -16,7 +16,7 @@
#include <QLocale>
#include <QPair>
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

View File

@ -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 );
}
}

View File

@ -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

View File

@ -18,7 +18,7 @@
#include <QObject>
#include <QString>
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

View File

@ -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

View File

@ -19,7 +19,7 @@
#include <QVector>
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

View File

@ -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 );
}

View File

@ -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 <prefix><locale> 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.
*

View File

@ -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();

View File

@ -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)";

View File

@ -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;

View File

@ -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() );
}

View File

@ -63,7 +63,7 @@ private:
Ui::WelcomePage* ui;
CheckerContainer* m_checkingWidget;
CalamaresUtils::Locale::TranslationsModel* m_languages;
Calamares::Locale::TranslationsModel* m_languages;
Config* m_conf;
};