Commit f58842f0 authored by Simon Depiets's avatar Simon Depiets

Function that returns the list of Language Codes

parent c6e360f0
......@@ -44,6 +44,11 @@ class KLanguageNameTest : public QObject
Q_OBJECT
private Q_SLOTS:
void testListFound()
{
QVERIFY(KLanguageName::allLanguageCodes().count() > 0);
}
void testNameForCode()
{
// This is somewhat wrong, it should not say US.
......
......@@ -24,6 +24,8 @@
#include <KConfig>
#include <KConfigGroup>
#include <QDir>
QString KLanguageName::nameForCode(const QString &code)
{
const QStringList parts = QLocale().name().split(QLatin1Char('_'));
......@@ -65,3 +67,18 @@ QString KLanguageName::nameForCodeInLocale(const QString &code, const QString &o
return QString();
}
QStringList KLanguageName::allLanguageCodes()
{
QStringList systemLangList;
const QString localeDir = QStandardPaths::locate(QStandardPaths::GenericDataLocation,
QStringLiteral("locale"), QStandardPaths::LocateDirectory);
const QStringList entries = QDir(localeDir).entryList(QDir::Dirs);
for (QStringList::const_iterator language = entries.constBegin(); language != entries.constEnd(); ++language) {
const QString entryFile = localeDir + '/' + *language + "/kf5_entry.desktop";
if (QFile::exists(entryFile)) {
systemLangList.append(*language);
}
}
return systemLangList;
}
......@@ -25,6 +25,7 @@
#include "kconfigwidgets_export.h"
class QString;
class QStringList;
/**
* @class KLanguageName klanguagename.h KLanguageName
......@@ -58,6 +59,14 @@ namespace KLanguageName
* @param outputLocale code (ISO 639-1) of the language in which we want the name in.
*/
KCONFIGWIDGETS_EXPORT QString nameForCodeInLocale(const QString &code, const QString &outputLocale);
/**
* Returns the list of language codes found on the system
* as having kf5_entry.desktop files.
*
* @since 5.73
*/
KCONFIGWIDGETS_EXPORT QStringList allLanguageCodes();
}
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment