From e7d0f205a40a46efdccdfa434f02054dc7ff5279 Mon Sep 17 00:00:00 2001 From: Kevin Kofler Date: Tue, 25 Nov 2014 20:03:37 +0100 Subject: [PATCH] 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. --- src/modules/locale/LocalePage.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/modules/locale/LocalePage.cpp b/src/modules/locale/LocalePage.cpp index 6420534a5..58353e11b 100644 --- a/src/modules/locale/LocalePage.cpp +++ b/src/modules/locale/LocalePage.cpp @@ -30,6 +30,7 @@ #include #include #include +#include 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() == "#" )