// SPDX-FileCopyrightText: 2026 Matvey Shcherbinin // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL #pragma once #include #include #include #include #include // The languages this build can actually speak, read off the directory the // catalogs are loaded from. // // A list written out in QML is a list that goes out of date: it offers languages // nobody has translated - choosing one gets you the source strings and a // language you did not ask for - and it misses the one a translator finished last // week until somebody remembers to edit the array. The directory is the one // main.cpp hands to KLocalizedString, so what is offered here is what can // really be loaded. // // The empty code is not a directory entry and does not come from one: it is the // system language, which is what the application speaks until a language is // picked, and the source language is always on the list whether or not a // catalog for it was ever built, because it is the strings in the code. class TranslationCatalog : public QObject { Q_OBJECT QML_ELEMENT QML_SINGLETON // [{ code, displayName }] - code is what is stored, displayName what is // drawn, and the name is the language's own rather than its name in this // program's language, so the list is readable to the person choosing. Q_PROPERTY(QVariantList languages READ languages CONSTANT) public: explicit TranslationCatalog(QObject *parent = nullptr); static TranslationCatalog *create(QQmlEngine *, QJSEngine *); QVariantList languages() const { return m_languages; } // Where catalogs are looked for, in the order they are tried: the first // candidate holding a koutnet.mo is the one the application loads from, and // so the one this lists. Public because main.cpp is what loads them, and a // second copy of this list of paths is a second answer to the same question. static QString localeDir(); // The codes with a catalog in dir, a bare directory listing, no gettext // layout knowledge in it. A catalog is looked for both where gettext puts // one (/LC_MESSAGES/koutnet.mo) and directly under the code // (/koutnet.mo), which is what a plain directory of hand-made // catalogs looks like. static QStringList localeCodesIn(const QString &dir); // What a code is called by the person who speaks it: "Русский", not // "Russian", and the territory in its own spelling when the code names one. static QString displayNameFor(const QString &code); private: void build(); QVariantList m_languages; };