Repository: nomic-ai/gpt4all
File: gpt4all-chat/mysettings.cpp (C++)

Code before:
        if (!skipKompute || strcmp(d.backend, "kompute"))
            deviceList << QString::fromStdString(d.selectionName());
    }
#endif
    deviceList << "CPU";
    return deviceList;
}

static QString getUiLanguage(const QString directory, const QString fileName)
{
    QTranslator translator;
    const QString filePath = directory + QDir::separator() + fileName;
    if (translator.load(filePath)) {
        const QString lang = fileName.mid(fileName.indexOf('_') + 1,
            fileName.lastIndexOf('.') - fileName.indexOf('_') - 1);
        return lang;
    }

    qDebug() << "ERROR: Failed to load translation file:" << filePath;
    return QString();
}

static QStringList getUiLanguages(const QString &modelPath)
{
    QStringList languageList;
    QStringList releasedLanguages = { "en_US", "it_IT", "zh_CN", "zh_TW" };

    // Add the language translations from model path files first which is used by translation developers
    // to load translations in progress without having to rebuild all of GPT4All from source
    {
        const QDir dir(modelPath);
        const QStringList qmFiles = dir.entryList({"*.qm"}, QDir::Files);
        for (const QString &fileName : qmFiles)
            languageList << getUiLanguage(modelPath, fileName);
    }

    // Now add the internal language translations
    {
        const QDir dir(":/i18n");
        const QStringList qmFiles = dir.entryList({"*.qm"}, QDir::Files);
        for (const QString &fileName : qmFiles) {
            const QString lang = getUiLanguage(":/i18n", fileName);
            if (!languageList.contains(lang) && releasedLanguages.contains(lang))
                languageList.append(lang);
        }
    }
    return languageList;
}

class MyPrivateSettings: public MySettings { };
Q_GLOBAL_STATIC(MyPrivateSettings, settingsInstance)

Review comment (suggestion):
releasedLanguages should be static const. We could avoid the runtime constructor if we used std::ranges::find with a C-style array or std::array, but that's not a big deal.
```suggestion
    static const QStringList releasedLanguages { "en_US", "it_IT", "zh_CN", "zh_TW" };
    QStringList languageList;
```

Code after:
        if (!skipKompute || strcmp(d.backend, "kompute"))
            deviceList << QString::fromStdString(d.selectionName());
    }
#endif
    deviceList << "CPU";
    return deviceList;
}

static QString getUiLanguage(const QString directory, const QString fileName)
{
    QTranslator translator;
    const QString filePath = directory + QDir::separator() + fileName;
    if (translator.load(filePath)) {
        const QString lang = fileName.mid(fileName.indexOf('_') + 1,
            fileName.lastIndexOf('.') - fileName.indexOf('_') - 1);
        return lang;
    }

    qDebug() << "ERROR: Failed to load translation file:" << filePath;
    return QString();
}

static QStringList getUiLanguages(const QString &modelPath)
{
    QStringList languageList;
    static const QStringList releasedLanguages = { "en_US", "it_IT", "zh_CN", "zh_TW", "es_MX", "pt_BR", "ro_RO" };

    // Add the language translations from model path files first which is used by translation developers
    // to load translations in progress without having to rebuild all of GPT4All from source
    {
        const QDir dir(modelPath);
        const QStringList qmFiles = dir.entryList({"*.qm"}, QDir::Files);
        for (const QString &fileName : qmFiles)
            languageList << getUiLanguage(modelPath, fileName);
    }

    // Now add the internal language translations
    {
        const QDir dir(":/i18n");
        const QStringList qmFiles = dir.entryList({"*.qm"}, QDir::Files);
        for (const QString &fileName : qmFiles) {
            const QString lang = getUiLanguage(":/i18n", fileName);
            if (!languageList.contains(lang) && releasedLanguages.contains(lang))
                languageList.append(lang);
        }
    }
    return languageList;
}

class MyPrivateSettings: public MySettings { };
Q_GLOBAL_STATIC(MyPrivateSettings, settingsInstance)