Merge branch 'calamares' into issues-1166
This commit is contained in:
commit
62579e0f42
@ -140,20 +140,18 @@ set( CALAMARES_DESCRIPTION_SUMMARY
|
||||
# TODO: drop the es_ES translation from Transifex
|
||||
#
|
||||
# NOTE: move eo (Esperanto) to _ok once Qt can actually create a
|
||||
# locale for it. (Qt 5.12.2 can, see check later on).
|
||||
# NOTE: update these lines by running txstats.py, or copy these four lines
|
||||
# and prefix each variable name with "p", so that the automatic
|
||||
# checks for new languages and misspelled ones are done (that is,
|
||||
# copy these four lines to four backup lines, add "p", and then update
|
||||
# the original four lines with the current translations).
|
||||
# locale for it. (Qt 5.12.2 can, see Translation Status section).
|
||||
# NOTE: move ie (Interlingue) to _ok once Qt supports it.
|
||||
# NOTE: update these lines by running `txstats.py`, or for full automation
|
||||
# `txstats.py -e`. See also
|
||||
#
|
||||
# Total 68 languages
|
||||
set( _tx_complete ca fi_FI he hr nl pt_BR sq tg tr_TR uk zh_TW )
|
||||
set( _tx_good as ast az az_AZ be cs_CZ da de es fr hi hu it_IT ja
|
||||
ko lt ml pt_PT ru sk sv zh_CN )
|
||||
set( _tx_ok ar bg el en_GB es_MX es_PR et eu fa gl id ie is mr nb
|
||||
set( _tx_ok ar bg el en_GB es_MX es_PR et eu fa gl id is mr nb
|
||||
pl ro sl sr sr@latin th )
|
||||
set( _tx_incomplete bn ca@valencia eo fr_CH gu kk kn lo lv mk ne_NP
|
||||
set( _tx_incomplete bn ca@valencia eo fr_CH gu ie kk kn lo lv mk ne_NP
|
||||
ur uz )
|
||||
|
||||
### Required versions
|
||||
@ -286,14 +284,6 @@ find_package( Qt5 ${QT_VERSION} CONFIG REQUIRED Concurrent Core Gui LinguistTool
|
||||
if( WITH_QML )
|
||||
find_package( Qt5 ${QT_VERSION} CONFIG REQUIRED Quick QuickWidgets )
|
||||
endif()
|
||||
if( Qt5_VERSION VERSION_GREATER 5.12.1 )
|
||||
# At least Qt 5.12.2 seems to support Esperanto in QLocale
|
||||
if( "eo" IN_LIST _tx_incomplete )
|
||||
message(STATUS "Esperanto support since Qt 5.12.2, enabling Esperanto locale")
|
||||
list( REMOVE_ITEM _tx_incomplete "eo" )
|
||||
list( APPEND _tx_ok "eo" )
|
||||
endif()
|
||||
endif()
|
||||
# Optional Qt parts
|
||||
find_package( Qt5DBus CONFIG )
|
||||
|
||||
@ -429,30 +419,22 @@ set(Calamares_WITH_QML ${WITH_QML})
|
||||
|
||||
### Transifex Translation status
|
||||
#
|
||||
# Construct language lists for use. If there are p_tx* variables,
|
||||
# then run an extra cmake-time check for consistency of the old
|
||||
# (p_tx*) and new (_tx*) lists.
|
||||
# Construct language lists for use.
|
||||
#
|
||||
set( prev_tx ${p_tx_complete} ${p_tx_good} ${p_tx_ok} ${p_tx_incomplete} )
|
||||
if( Qt5_VERSION VERSION_GREATER 5.12.1 )
|
||||
# At least Qt 5.12.2 seems to support Esperanto in QLocale
|
||||
if( "eo" IN_LIST _tx_incomplete )
|
||||
message(STATUS "Esperanto support since Qt 5.12.2, enabling Esperanto locale")
|
||||
list( REMOVE_ITEM _tx_incomplete "eo" )
|
||||
list( APPEND _tx_ok "eo" )
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set( curr_tx ${_tx_complete} ${_tx_good} ${_tx_ok} ${_tx_incomplete} )
|
||||
set( tx_errors OFF )
|
||||
if ( prev_tx )
|
||||
# Gone in new list
|
||||
foreach( l ${prev_tx} )
|
||||
list( FIND curr_tx ${l} p_l )
|
||||
if( p_l EQUAL -1 )
|
||||
message(WARNING "Language ${l} was present in previous translations and is now absent.")
|
||||
set( tx_errors ON )
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if ( curr_tx )
|
||||
# New in list
|
||||
foreach( l ${curr_tx} )
|
||||
list( FIND prev_tx ${l} p_l )
|
||||
if( p_l EQUAL -1 )
|
||||
message(WARNING "Language ${l} is new.")
|
||||
set( tx_errors ON )
|
||||
endif()
|
||||
set( p_l "lang/calamares_${l}.ts" )
|
||||
if( NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${p_l} )
|
||||
message(WARNING "Language ${l} has no .ts file yet.")
|
||||
@ -463,7 +445,6 @@ if ( prev_tx )
|
||||
unset( p_l )
|
||||
unset( l )
|
||||
endif()
|
||||
unset( prev_tx )
|
||||
unset( curr_tx )
|
||||
if( tx_errors )
|
||||
message( FATAL_ERROR "Translation warnings, see above." )
|
||||
|
@ -178,6 +178,7 @@ def get_tx_stats(languages, outputter, verbose):
|
||||
# and it's at-the-least ok.
|
||||
incomplete_languages = (
|
||||
"eo", # Not supported by QLocale < 5.12.1
|
||||
"ie", # Not supported by Qt at least through 5.15.0
|
||||
)
|
||||
|
||||
all_langs = []
|
||||
|
@ -1,6 +1,7 @@
|
||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
*
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2019 Adriaan de Groot <groot@kde.org>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* Calamares is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -15,13 +16,8 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* License-Filename: LICENSE
|
||||
*
|
||||
*/
|
||||
|
||||
#include "Tests.h"
|
||||
|
||||
#include "locale/LabelModel.h"
|
||||
#include "locale/TimeZone.h"
|
||||
#include "locale/TranslatableConfiguration.h"
|
||||
@ -31,7 +27,29 @@
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
QTEST_GUILESS_MAIN( LocaleTests )
|
||||
class LocaleTests : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
LocaleTests();
|
||||
~LocaleTests() override;
|
||||
|
||||
private Q_SLOTS:
|
||||
void initTestCase();
|
||||
|
||||
void testLanguageModelCount();
|
||||
void testTranslatableLanguages();
|
||||
void testTranslatableConfig1();
|
||||
void testTranslatableConfig2();
|
||||
void testLanguageScripts();
|
||||
|
||||
void testEsperanto();
|
||||
void testInterlingue();
|
||||
|
||||
// TimeZone testing
|
||||
void testSimpleZones();
|
||||
void testComplexZones();
|
||||
};
|
||||
|
||||
LocaleTests::LocaleTests() {}
|
||||
|
||||
@ -40,6 +58,8 @@ LocaleTests::~LocaleTests() {}
|
||||
void
|
||||
LocaleTests::initTestCase()
|
||||
{
|
||||
Logger::setupLogLevel( Logger::LOGDEBUG );
|
||||
|
||||
// Otherwise plain get() is dubious in the TranslatableConfiguration tests
|
||||
QLocale::setDefault( QLocale( QStringLiteral( "en_US" ) ) );
|
||||
QVERIFY( ( QLocale().name() == "C" ) || ( QLocale().name() == "en_US" ) );
|
||||
@ -65,10 +85,8 @@ LocaleTests::testLanguageModelCount()
|
||||
}
|
||||
|
||||
void
|
||||
LocaleTests::testEsperanto()
|
||||
LocaleTests::testLanguageScripts()
|
||||
{
|
||||
Logger::setupLogLevel( Logger::LOGDEBUG );
|
||||
|
||||
const auto* m = CalamaresUtils::Locale::availableTranslations();
|
||||
|
||||
QVERIFY( m );
|
||||
@ -89,13 +107,33 @@ LocaleTests::testEsperanto()
|
||||
QVERIFY( locale.language() == QLocale::Lithuanian ? locale.country() == QLocale::Lithuania : true );
|
||||
QVERIFY( locale.language() != QLocale::C );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
LocaleTests::testEsperanto()
|
||||
{
|
||||
#if QT_VERSION < QT_VERSION_CHECK( 5, 12, 2 )
|
||||
QCOMPARE( QLocale( "eo" ).language(), QLocale::C );
|
||||
#else
|
||||
QCOMPARE( QLocale( "eo" ).language(), QLocale::Esperanto );
|
||||
#endif
|
||||
QCOMPARE( QLocale( QLocale::Esperanto ).language(), QLocale::Esperanto ); // Probably fails on 5.12, too
|
||||
}
|
||||
|
||||
void
|
||||
LocaleTests::testInterlingue()
|
||||
{
|
||||
// ie / Interlingue is borked (is "ie" even the right name?)
|
||||
QCOMPARE( QLocale( "ie" ).language(), QLocale::C );
|
||||
QCOMPARE( QLocale( QLocale::Interlingue ).language(), QLocale::English );
|
||||
|
||||
// "ia" exists (post-war variant of Interlingue)
|
||||
QCOMPARE( QLocale( "ia" ).language(), QLocale::Interlingua );
|
||||
// "bork" does not exist
|
||||
QCOMPARE( QLocale( "bork" ).language(), QLocale::C );
|
||||
}
|
||||
|
||||
|
||||
static const QStringList&
|
||||
someLanguages()
|
||||
{
|
||||
@ -257,3 +295,9 @@ LocaleTests::testComplexZones()
|
||||
QCOMPARE( r.tr(), QStringLiteral( "zxc,;* vm" ) ); // Only _ is special
|
||||
}
|
||||
}
|
||||
|
||||
QTEST_GUILESS_MAIN( LocaleTests )
|
||||
|
||||
#include "utils/moc-warnings.h"
|
||||
|
||||
#include "Tests.moc"
|
||||
|
@ -1,49 +0,0 @@
|
||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2019 Adriaan de Groot <groot@kde.org>
|
||||
*
|
||||
* Calamares is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Calamares is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* License-Filename: LICENSE
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LIBCALAMARES_LOCALE_TESTS_H
|
||||
#define LIBCALAMARES_LOCALE_TESTS_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class LocaleTests : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
LocaleTests();
|
||||
~LocaleTests() override;
|
||||
|
||||
private Q_SLOTS:
|
||||
void initTestCase();
|
||||
|
||||
void testLanguageModelCount();
|
||||
void testEsperanto();
|
||||
void testTranslatableLanguages();
|
||||
void testTranslatableConfig1();
|
||||
void testTranslatableConfig2();
|
||||
|
||||
// TimeZone testing
|
||||
void testSimpleZones();
|
||||
void testComplexZones();
|
||||
};
|
||||
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
*
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2018 Adriaan de Groot <groot@kde.org>
|
||||
*
|
||||
*
|
||||
@ -26,6 +26,8 @@
|
||||
#include "CalamaresUtilsSystem.h"
|
||||
#include "Entropy.h"
|
||||
#include "Logger.h"
|
||||
#include "RAII.h"
|
||||
#include "Traits.h"
|
||||
#include "UMask.h"
|
||||
#include "Yaml.h"
|
||||
|
||||
@ -114,15 +116,16 @@ findConf( const QDir& d )
|
||||
return mine;
|
||||
}
|
||||
|
||||
void LibCalamaresTests::recursiveCompareMap(const QVariantMap& a, const QVariantMap& b, int depth )
|
||||
void
|
||||
LibCalamaresTests::recursiveCompareMap( const QVariantMap& a, const QVariantMap& b, int depth )
|
||||
{
|
||||
cDebug() << "Comparing depth" << depth << a.count() << b.count();
|
||||
QCOMPARE( a.keys(), b.keys() );
|
||||
for ( const auto& k : a.keys() )
|
||||
{
|
||||
cDebug() << Logger::SubEntry << k;
|
||||
const auto& av = a[k];
|
||||
const auto& bv = b[k];
|
||||
const auto& av = a[ k ];
|
||||
const auto& bv = b[ k ];
|
||||
|
||||
if ( av.typeName() != bv.typeName() )
|
||||
{
|
||||
@ -130,9 +133,9 @@ void LibCalamaresTests::recursiveCompareMap(const QVariantMap& a, const QVariant
|
||||
cDebug() << Logger::SubEntry << "b type" << bv.typeName() << bv;
|
||||
}
|
||||
QCOMPARE( av.typeName(), bv.typeName() );
|
||||
if ( av.canConvert<QVariantMap>() )
|
||||
if ( av.canConvert< QVariantMap >() )
|
||||
{
|
||||
recursiveCompareMap( av.toMap(), bv.toMap(), depth+1 );
|
||||
recursiveCompareMap( av.toMap(), bv.toMap(), depth + 1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -289,3 +292,77 @@ LibCalamaresTests::testOddSizedPrintable()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
LibCalamaresTests::testBoolSetter()
|
||||
{
|
||||
bool b = false;
|
||||
|
||||
QVERIFY( !b );
|
||||
{
|
||||
QVERIFY( !b );
|
||||
cBoolSetter< true > x( b );
|
||||
QVERIFY( b );
|
||||
}
|
||||
QVERIFY( !b );
|
||||
|
||||
QVERIFY( !b );
|
||||
{
|
||||
QVERIFY( !b );
|
||||
cBoolSetter< false > x( b );
|
||||
QVERIFY( !b ); // Still!
|
||||
}
|
||||
QVERIFY( b );
|
||||
}
|
||||
|
||||
/* Demonstration of Traits support for has-a-method or not.
|
||||
*
|
||||
* We have two classes, c1 and c2; one has a method do_the_thing() and the
|
||||
* other does not. A third class, Thinginator, has a method thingify(),
|
||||
* which should call do_the_thing() of its argument if it exists.
|
||||
*/
|
||||
|
||||
struct c1 { int do_the_thing() { return 2; } };
|
||||
struct c2 { };
|
||||
|
||||
DECLARE_HAS_METHOD(do_the_thing)
|
||||
|
||||
struct Thinginator
|
||||
{
|
||||
public:
|
||||
/// When class T has function do_the_thing()
|
||||
template< class T > int thingify( T& t, const std::true_type& )
|
||||
{
|
||||
return t.do_the_thing();
|
||||
}
|
||||
|
||||
template< class T > int thingify( T&, const std::false_type& )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
template< class T > int thingify( T& t )
|
||||
{
|
||||
return thingify(t, has_do_the_thing<T>{});
|
||||
}
|
||||
} ;
|
||||
|
||||
|
||||
void
|
||||
LibCalamaresTests::testTraits()
|
||||
{
|
||||
has_do_the_thing<c1> x{};
|
||||
has_do_the_thing<c2> y{};
|
||||
|
||||
QVERIFY(x);
|
||||
QVERIFY(!y);
|
||||
|
||||
c1 c1{};
|
||||
c2 c2{};
|
||||
|
||||
QCOMPARE(c1.do_the_thing(), 2);
|
||||
|
||||
Thinginator t;
|
||||
QCOMPARE(t.thingify(c1), 2); // Calls c1::do_the_thing()
|
||||
QCOMPARE(t.thingify(c2), -1);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
*
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2018 Adriaan de Groot <groot@kde.org>
|
||||
*
|
||||
*
|
||||
@ -50,6 +50,12 @@ private Q_SLOTS:
|
||||
void testPrintableEntropy();
|
||||
void testOddSizedPrintable();
|
||||
|
||||
/** @brief Tests the RAII bits. */
|
||||
void testBoolSetter();
|
||||
|
||||
/** @brief Tests the Traits bits. */
|
||||
void testTraits();
|
||||
|
||||
private:
|
||||
void recursiveCompareMap( const QVariantMap& a, const QVariantMap& b, int depth );
|
||||
};
|
||||
|
77
src/libcalamares/utils/Traits.h
Normal file
77
src/libcalamares/utils/Traits.h
Normal file
@ -0,0 +1,77 @@
|
||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2020 Adriaan de Groot <groot@kde.org>
|
||||
*
|
||||
* Calamares is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Calamares is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* License-Filename: LICENSE
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef UTILS_TRAITS_H
|
||||
#define UTILS_TRAITS_H
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
|
||||
namespace CalamaresUtils
|
||||
{
|
||||
|
||||
/** @brief Traits machinery lives in this namespace
|
||||
*
|
||||
* The primary purpose of this namespace is to hold machinery that
|
||||
* is created by the DECLARE_HAS_METHOD macro.
|
||||
*
|
||||
* The DECLARE_HAS_METHOD macro builds machinery to check whether
|
||||
* a class has a particular named method. This can be used to
|
||||
* specialize templates elsewhere for use with classes with, or without,
|
||||
* the named method.
|
||||
*
|
||||
* To use the machinery (which is not that sophisticated):
|
||||
*
|
||||
* - Put `DECLARE_HAS_METHOD(myFunction)` somewhere in file scope.
|
||||
* This puts together the machinery for detecting if `myFunction`
|
||||
* is a method of some class.
|
||||
* - At global scope, `has_myFunction<T>` is now either std::true_type,
|
||||
* if the type `T` has a method `T::myFunction`, or std::false_type,
|
||||
* if it does not.
|
||||
*
|
||||
* To specialize template methods based on the presence of the named
|
||||
* method, write **three** overloads:
|
||||
*
|
||||
* - `template<class T> myMethod(args ..., const std::true_type& )`
|
||||
* This is the implementation where class T has `myFunction`.
|
||||
* - `template<class T> myMethod(args ..., const std::false_type& )`
|
||||
* This is the implementation without.
|
||||
* - `template<class T> myMethod(args ...)` is the general implementation,
|
||||
* which can call the specialized implementations with
|
||||
* `return myMethod(args ..., has_myFunction<T>{})`
|
||||
*/
|
||||
namespace Traits
|
||||
{
|
||||
template< class > struct sfinae_true : std::true_type{};
|
||||
}
|
||||
}
|
||||
|
||||
#define DECLARE_HAS_METHOD(m) \
|
||||
namespace CalamaresUtils { namespace Traits { \
|
||||
struct has_ ## m { \
|
||||
template< class T > static auto f(int) -> sfinae_true<decltype(&T:: m)>; \
|
||||
template< class T > static auto f(long) -> std::false_type; \
|
||||
template< class T > using t = decltype( f <T>(0) ); \
|
||||
}; } } \
|
||||
template< class T > using has_ ## m = CalamaresUtils::Traits:: has_ ## m ::t<T>;
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user