Python-i18n: (inefficiently) search for suitable gettext dirs
This commit is contained in:
parent
40335d9f1e
commit
3a1d5ed533
@ -27,7 +27,9 @@
|
|||||||
#include "GlobalStorage.h"
|
#include "GlobalStorage.h"
|
||||||
#include "JobQueue.h"
|
#include "JobQueue.h"
|
||||||
|
|
||||||
|
#include <QCoreApplication>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QStandardPaths>
|
||||||
|
|
||||||
#undef slots
|
#undef slots
|
||||||
#include <boost/python.hpp>
|
#include <boost/python.hpp>
|
||||||
@ -203,10 +205,10 @@ obscure( const std::string& string )
|
|||||||
return CalamaresUtils::obscure( QString::fromStdString( string ) ).toStdString();
|
return CalamaresUtils::obscure( QString::fromStdString( string ) ).toStdString();
|
||||||
}
|
}
|
||||||
|
|
||||||
bp::list
|
static QStringList
|
||||||
gettext_languages()
|
_gettext_languages()
|
||||||
{
|
{
|
||||||
bp::list pyList;
|
QStringList languages;
|
||||||
|
|
||||||
// There are two ways that Python jobs can be initialised:
|
// There are two ways that Python jobs can be initialised:
|
||||||
// - through JobQueue, in which case that has an instance which holds
|
// - through JobQueue, in which case that has an instance which holds
|
||||||
@ -224,27 +226,64 @@ gettext_languages()
|
|||||||
if ( lang_.canConvert< QString >() )
|
if ( lang_.canConvert< QString >() )
|
||||||
{
|
{
|
||||||
QString lang = lang_.value< QString >();
|
QString lang = lang_.value< QString >();
|
||||||
pyList.append( lang.toStdString() );
|
languages.append(lang);
|
||||||
if ( lang.indexOf( '.' ) > 0)
|
if ( lang.indexOf( '.' ) > 0)
|
||||||
{
|
{
|
||||||
lang.truncate( lang.indexOf( '.' ) );
|
lang.truncate( lang.indexOf( '.' ) );
|
||||||
pyList.append( lang.toStdString() );
|
languages.append(lang);
|
||||||
}
|
}
|
||||||
if ( lang.indexOf( '_' ) > 0)
|
if ( lang.indexOf( '_' ) > 0)
|
||||||
{
|
{
|
||||||
lang.truncate( lang.indexOf( '_' ) );
|
lang.truncate( lang.indexOf( '_' ) );
|
||||||
|
languages.append(lang);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return languages;
|
||||||
|
}
|
||||||
|
|
||||||
|
bp::list
|
||||||
|
gettext_languages()
|
||||||
|
{
|
||||||
|
bp::list pyList;
|
||||||
|
for (auto lang : _gettext_languages())
|
||||||
pyList.append( lang.toStdString() );
|
pyList.append( lang.toStdString() );
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return pyList;
|
return pyList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_add_localedirs(QStringList &pathList, const QString &candidate)
|
||||||
|
{
|
||||||
|
if (!candidate.isEmpty())
|
||||||
|
{
|
||||||
|
pathList.prepend(candidate);
|
||||||
|
if (QDir(candidate).cd("lang"))
|
||||||
|
{
|
||||||
|
pathList.prepend(candidate + "/lang");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bp::object
|
bp::object
|
||||||
gettext_path()
|
gettext_path()
|
||||||
{
|
{
|
||||||
// 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 = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "locale", QStandardPaths::LocateDirectory);
|
||||||
|
QString extra = QCoreApplication::applicationDirPath();
|
||||||
|
_add_localedirs(candidatePaths, extra);
|
||||||
|
_add_localedirs(candidatePaths, QDir().canonicalPath());
|
||||||
|
|
||||||
|
cDebug() << "Standard paths" << candidatePaths;
|
||||||
|
|
||||||
|
for (auto lang : _gettext_languages())
|
||||||
|
for (auto localedir : candidatePaths)
|
||||||
|
{
|
||||||
|
QDir ldir(localedir);
|
||||||
|
cDebug() << "Checking" << lang << "in" <<ldir.canonicalPath();
|
||||||
|
if (ldir.cd(lang))
|
||||||
|
return bp::object( localedir.toStdString() );
|
||||||
|
}
|
||||||
return bp::object(); // None
|
return bp::object(); // None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user