[libcalamares] Log the Python language-search process just once

- log the list of search paths once
- log the found-language as if from Python
- warn always if none are found
This commit is contained in:
Adriaan de Groot 2021-09-22 11:03:56 +02:00
parent 7bdccd0ea7
commit b0149c2712

View File

@ -16,6 +16,7 @@
#include "partition/Mount.h" #include "partition/Mount.h"
#include "utils/CalamaresUtilsSystem.h" #include "utils/CalamaresUtilsSystem.h"
#include "utils/Logger.h" #include "utils/Logger.h"
#include "utils/RAII.h"
#include "utils/String.h" #include "utils/String.h"
#include <QCoreApplication> #include <QCoreApplication>
@ -147,7 +148,7 @@ debug( const std::string& s )
void void
warning( const std::string& s ) warning( const std::string& s )
{ {
Logger::CDebug( Logger::LOGWARNING ) << output_prefix << QString::fromStdString( s ); Logger::CDebug( Logger::LOGWARNING ) << output_prefix << QString::fromStdString( s );
} }
PythonJobInterface::PythonJobInterface( Calamares::PythonJob* parent ) PythonJobInterface::PythonJobInterface( Calamares::PythonJob* parent )
@ -241,6 +242,10 @@ _add_localedirs( QStringList& pathList, const QString& candidate )
bp::object bp::object
gettext_path() gettext_path()
{ {
// Going to log informatively just once
static bool first_time = true;
cPointerSetter( &first_time, false );
// TODO: distinguish between -d runs and normal runs // TODO: distinguish between -d runs and normal runs
// TODO: can we detect DESTDIR-installs? // TODO: can we detect DESTDIR-installs?
QStringList candidatePaths QStringList candidatePaths
@ -257,21 +262,26 @@ gettext_path()
} }
_add_localedirs( candidatePaths, QDir().canonicalPath() ); // . _add_localedirs( candidatePaths, QDir().canonicalPath() ); // .
cDebug() << "Determining gettext path from" << candidatePaths; if ( first_time )
{
cDebug() << "Determining gettext path from" << candidatePaths;
}
QStringList candidateLanguages = _gettext_languages(); QStringList candidateLanguages = _gettext_languages();
for ( const auto& lang : candidateLanguages ) for ( const auto& lang : candidateLanguages )
{
for ( auto localedir : candidatePaths ) for ( auto localedir : candidatePaths )
{ {
QDir ldir( localedir ); QDir ldir( localedir );
if ( ldir.cd( lang ) ) if ( ldir.cd( lang ) )
{ {
cDebug() << Logger::SubEntry << "Found" << lang << "in" << ldir.canonicalPath(); Logger::CDebug( Logger::LOGDEBUG )
<< output_prefix << "Found gettext" << lang << "in" << ldir.canonicalPath();
return bp::object( localedir.toStdString() ); return bp::object( localedir.toStdString() );
} }
} }
cDebug() << Logger::SubEntry << "No translation found for languages" << candidateLanguages; }
cWarning() << "No translation found for languages" << candidateLanguages;
return bp::object(); // None return bp::object(); // None
} }