[education/gcompris] /: core, add commandline option to select a locale
Johnny Jazeix
null at kde.org
Fri Nov 28 09:13:16 GMT 2025
Git commit ab9cdc423c216daf6c94d0e6f15dfdd05f5a2dab by Johnny Jazeix.
Committed on 28/11/2025 at 09:12.
Pushed by jjazeix into branch 'master'.
core, add commandline option to select a locale
M +4 -0 docs/docbook/index.docbook
M +9 -10 src/core/ApplicationInfo.cpp
M +1 -1 src/core/ApplicationInfo.h
M +1 -0 src/core/ChangeLog.qml
M +17 -0 src/core/main.cpp
https://invent.kde.org/education/gcompris/-/commit/ab9cdc423c216daf6c94d0e6f15dfdd05f5a2dab
diff --git a/docs/docbook/index.docbook b/docs/docbook/index.docbook
index 62f0ae5212..f85b4d6e68 100644
--- a/docs/docbook/index.docbook
+++ b/docs/docbook/index.docbook
@@ -328,6 +328,10 @@ or make it show real car images instead of filled rectangles (traffic).</para>
<entry>--opengl-renderer</entry>
<entry>Use OpenGL renderer instead of software (faster and more graphical effects but can crash with some graphical cards). Deprecated, use “--renderer=opengl” instead.</entry>
</row>
+<row>
+<entry>--locale=locale</entry>
+<entry>Run &gcompris; with the specified locale.</entry>
+</row>
</tbody>
</tgroup>
</informaltable>
diff --git a/src/core/ApplicationInfo.cpp b/src/core/ApplicationInfo.cpp
index df390908c1..288cdd6b33 100644
--- a/src/core/ApplicationInfo.cpp
+++ b/src/core/ApplicationInfo.cpp
@@ -313,36 +313,35 @@ bool ApplicationInfo::loadAndroidTranslation(const QString &locale)
}
/**
- * Checks if the locale is supported. Locale may have been removed because
+ * Returns a list of supported locales. Locale may have been removed because
* translation progress was not enough or invalid language put in configuration.
*/
-bool ApplicationInfo::isSupportedLocale(const QString &locale)
+QStringList ApplicationInfo::supportedLocales()
{
- bool isSupported = false;
+ QStringList supportedLocales;
QQmlEngine engine;
QQmlComponent component(&engine, QUrl("qrc:/gcompris/src/core/LanguageList.qml"));
QObject *object = component.create();
if (!object) {
- qWarning() << "isSupportedLocale:" << component.errors();
- return false;
+ qWarning() << "supportedLocales:" << component.errors();
+ return supportedLocales;
}
QVariant variant = object->property("languages");
QJSValue languagesList = variant.value<QJSValue>();
const int length = languagesList.property("length").toInt();
for (int i = 0; i < length; ++i) {
- if (languagesList.property(i).property("locale").toString() == locale) {
- isSupported = true;
- }
+ supportedLocales << languagesList.property(i).property("locale").toString();
}
delete object;
- return isSupported;
+ return supportedLocales;
}
// Return the locale
QString ApplicationInfo::loadTranslation(const QString &requestedLocale)
{
QString locale = requestedLocale;
- if (!isSupportedLocale(locale)) {
+ QStringList locales = supportedLocales();
+ if (!locales.contains(locale)) {
qDebug() << "locale" << locale << "not supported, defaulting to" << GC_DEFAULT_LOCALE;
locale = GC_DEFAULT_LOCALE;
ApplicationSettings::getInstance()->setLocale(locale);
diff --git a/src/core/ApplicationInfo.h b/src/core/ApplicationInfo.h
index c86d6950fe..af843c67ad 100644
--- a/src/core/ApplicationInfo.h
+++ b/src/core/ApplicationInfo.h
@@ -295,6 +295,7 @@ public:
*/
void switchLocale();
void switchLocale(const QString &locale);
+ QStringList supportedLocales();
static QString GCVersion() { return VERSION; }
static int GCVersionCode() { return VERSION_CODE; }
@@ -479,7 +480,6 @@ private:
static QQuickWindow *m_window;
bool loadAndroidTranslation(const QString &locale);
- bool isSupportedLocale(const QString &locale);
QString loadTranslation(const QString &requestedLocale);
};
diff --git a/src/core/ChangeLog.qml b/src/core/ChangeLog.qml
index 806cf93e9d..ef0ae5c3bc 100644
--- a/src/core/ChangeLog.qml
+++ b/src/core/ChangeLog.qml
@@ -28,6 +28,7 @@ QtObject {
property var changelog: [
{ "versionCode": 260000, "content": [
qsTr("Translation added for Kannada and Tamil"),
+ qsTr("New command-line option to set the locale (--locale locale)"),
qsTr("Many usability improvements"),
qsTr("Many new images"),
qsTr("Many bug fixes")
diff --git a/src/core/main.cpp b/src/core/main.cpp
index 1ce570fbb4..62d9003c46 100644
--- a/src/core/main.cpp
+++ b/src/core/main.cpp
@@ -139,6 +139,10 @@ int main(int argc, char *argv[])
QObject::tr("Specify on which level to start the activity. Only used when --launch option is used."), "startLevel");
parser.addOption(clStartOnLevel);
+ QCommandLineOption clLocale("locale",
+ QObject::tr("Specify the locale when starting GCompris."), "locale");
+ parser.addOption(clLocale);
+
parser.process(app);
#ifdef WITH_RCC
@@ -201,6 +205,19 @@ int main(int argc, char *argv[])
if (parser.isSet(clWithKioskMode)) {
ApplicationSettings::getInstance()->setKioskMode(true);
}
+ if (parser.isSet(clLocale)) {
+ QString locale = parser.value(clLocale);
+ if (locale != "system") {
+ locale += QStringLiteral(".UTF-8");
+ }
+ QStringList allLocales = ApplicationInfo::getInstance()->supportedLocales();
+ if (!allLocales.contains(locale)) {
+ qDebug() << "supported locales are:" << allLocales.replaceInStrings(".UTF-8", "").join(", ");
+ }
+ else {
+ ApplicationSettings::getInstance()->setLocale(locale);
+ }
+ }
// This will be removed later, for now, it is ignored if --renderer option is set
if (parser.isSet(clSoftwareRenderer)) {
ApplicationSettings::getInstance()->setRenderer(QStringLiteral("software"));
More information about the kde-doc-english
mailing list