File indexing completed on 2024-10-06 05:12:14
0001 /* 0002 Copyright 2019 Harald Sitter <sitter@kde.org> 0003 0004 This program is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU General Public License as 0006 published by the Free Software Foundation; either version 3 of 0007 the License or any later version accepted by the membership of 0008 KDE e.V. (or its successor approved by the membership of KDE 0009 e.V.), which shall act as a proxy defined in Section 14 of 0010 version 3 of the license. 0011 0012 This program is distributed in the hope that it will be useful, 0013 but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0015 GNU General Public License for more details. 0016 0017 You should have received a copy of the GNU General Public License 0018 along with this program. If not, see <https://www.gnu.org/licenses/>. 0019 */ 0020 0021 #include <QDebug> 0022 #include <QLocale> 0023 #include <QQmlEngine> 0024 #include <QQmlExtensionPlugin> 0025 0026 #include <KDeclarative/KDeclarative> 0027 #include <KLocalizedString> 0028 #include <KLocalizedContext> 0029 0030 // Simple plugin that does absolutely nothing other than make i18n available 0031 // to QML with the slideshow translations as domain. 0032 // i.e. use the same translations as used for the ubiquity html but in their 0033 // gettext incarnation. 0034 class ContextPlugin : public QQmlExtensionPlugin 0035 { 0036 Q_OBJECT 0037 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") 0038 0039 public: 0040 void initializeEngine(QQmlEngine *engine, const char *uri) override 0041 { 0042 QQmlExtensionPlugin::initializeEngine(engine, uri); 0043 0044 KDeclarative::KDeclarative d; 0045 // The domain is unrelated to cala here. We recycle the same 0046 // translations from ubiquity for calamares. 0047 d.setTranslationDomain("ubiquity-slideshow-neon"); 0048 d.setDeclarativeEngine(engine); 0049 d.setupEngine(engine); 0050 d.setupContext(); 0051 0052 // Cala only sets the QLocale default but otherwise leaves 0053 // everything unchanged. That means ki18n will not pick the 0054 // correct reference as the "system" locale is still what it 0055 // was. To solve this we'll build the language list manually. 0056 QStringList ls; 0057 for (auto &lang : QLocale().uiLanguages()) { 0058 ls << lang.replace('-', '_'); 0059 } 0060 for (auto &lang : QLocale::system().uiLanguages()) { 0061 ls << lang.replace('-', '_'); 0062 } 0063 KLocalizedString::setLanguages(ls); 0064 } 0065 0066 void registerTypes(const char *uri) override 0067 { 0068 qmlRegisterModule(uri, 1, 0); 0069 } 0070 }; 0071 0072 #include "plugin.moc"