locale: Support distributions without locale-gen.
If /etc/locale.gen (or the configured localeGenPath) does not exist, assume that all the supported languages are already built into the locale archive, and retrieve the list from "locale -a". The list will then contain lines with only the locale rather than locale + space + encoding, but that should not affect any of the rest of the code. UTF-8 locales will still contain the string "UTF-8" (as part of the ".UTF-8" suffix), we will not write a locale.gen file if we don't have locale-gen, and everything else just strips away the encoding.
This commit is contained in:
parent
440b38addf
commit
e7d0f205a4
@ -30,6 +30,7 @@
|
||||
#include <QComboBox>
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QProcess>
|
||||
|
||||
|
||||
LocalePage::LocalePage( QWidget* parent )
|
||||
@ -226,12 +227,22 @@ LocalePage::init( const QString& initialRegion,
|
||||
// Fill in meaningful locale/charset lines from locale.gen
|
||||
m_localeGenLines.clear();
|
||||
QFile localeGen( localeGenPath );
|
||||
if ( !localeGen.open( QIODevice::ReadOnly | QIODevice::Text ) )
|
||||
QByteArray ba;
|
||||
if ( localeGen.open( QIODevice::ReadOnly | QIODevice::Text ) )
|
||||
{
|
||||
cDebug() << "ERROR: Cannot open file" << localeGenPath << ".";
|
||||
return;
|
||||
ba = localeGen.readAll();
|
||||
localeGen.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
cDebug() << "Cannot open file" << localeGenPath
|
||||
<< ". Assuming the supported languages are already built into "
|
||||
"the locale archive.";
|
||||
QProcess localeA;
|
||||
localeA.start( "locale", QStringList() << "-a" );
|
||||
localeA.waitForFinished();
|
||||
ba = localeA.readAllStandardOutput();
|
||||
}
|
||||
QByteArray ba = localeGen.readAll();
|
||||
foreach ( QByteArray line, ba.split( '\n' ) )
|
||||
{
|
||||
if ( line.startsWith( "# " ) || line.simplified() == "#" )
|
||||
|
Loading…
Reference in New Issue
Block a user