diff --git a/CMakeLists.txt b/CMakeLists.txt index cc3bc9a93..17f991645 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -118,11 +118,6 @@ if (PySide2_FOUND AND Shiboken2_FOUND AND Python3_FOUND) set(ENABLE_PYTHON_PLUGINS TRUE) endif() -find_package(Intl) -if (Intl_FOUND) - set(HAVE_LIBINTL TRUE) -endif() - # Git revision if (EXISTS "${CMAKE_SOURCE_DIR}/.git") find_package(Git QUIET) diff --git a/config.h.cmake b/config.h.cmake index b101ef2cc..d35648e5b 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -9,5 +9,3 @@ /* Disable DBus support */ #cmakedefine DISABLE_DBUS - -#cmakedefine01 HAVE_LIBINTL diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index d0ac1f48a..945676809 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -268,10 +268,6 @@ set(SRCS ${SRCS} webtab/webtab.cpp ) -if (HAVE_LIBINTL) - set(SRCS ${SRCS} plugins/qml/api/i18n/qmli18n.cpp) -endif() - if (WIN32) set(SRCS ${SRCS} other/registerqappassociation.cpp) endif() diff --git a/src/lib/plugins/qml/api/i18n/qmli18n.cpp b/src/lib/plugins/qml/api/i18n/qmli18n.cpp deleted file mode 100644 index abb7c365a..000000000 --- a/src/lib/plugins/qml/api/i18n/qmli18n.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* ============================================================ -* Falkon - Qt web browser -* Copyright (C) 2018 Anmol Gautam -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* ============================================================ */ -#include "qmli18n.h" -#include "qztools.h" -#include - -QmlI18n::QmlI18n(const QString &pluginName, QObject *parent) - : QObject(parent) -{ - m_pluginName = pluginName; - initTranslations(); -} - -void QmlI18n::initTranslations() -{ - m_domain = QString(QSL("falkon_%1")).arg(m_pluginName); - const QString localeDir = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QSL("locale"), QStandardPaths::LocateDirectory); - const bool isLanguageSet = qEnvironmentVariableIsSet("LANGUAGE"); - const QByteArray language = qgetenv("LANGUAGE"); - qputenv("LANGUAGE", QLocale::system().name().toUtf8()); - bindtextdomain(m_domain.toUtf8(), localeDir.toUtf8()); - if (!isLanguageSet) { - qunsetenv("LANGUAGE"); - } else { - qputenv("LANGUAGE", language); - } -} - -QString QmlI18n::i18n(const QString &string) -{ - return QString::fromUtf8(dgettext(m_domain.toUtf8(), string.toUtf8())); -} - -QString QmlI18n::i18np(const QString &string1, const QString &string2, int count) -{ - return QString::fromUtf8(dngettext(m_domain.toUtf8(), string1.toUtf8(), string2.toUtf8(), count)); -} diff --git a/src/lib/plugins/qml/api/i18n/qmli18n.h b/src/lib/plugins/qml/api/i18n/qmli18n.h deleted file mode 100644 index 6bc43c513..000000000 --- a/src/lib/plugins/qml/api/i18n/qmli18n.h +++ /dev/null @@ -1,46 +0,0 @@ -/* ============================================================ -* Falkon - Qt web browser -* Copyright (C) 2018 Anmol Gautam -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* ============================================================ */ -#pragma once - -#include - -extern "C" { -#include -} - -/** - * @brief The class exposing GNU Gettext to QML - */ -class QmlI18n : public QObject -{ - Q_OBJECT -public: - explicit QmlI18n(const QString &pluginName, QObject *parent = nullptr); - void initTranslations(); - /** - * @brief wrapper for gettext function - */ - Q_INVOKABLE QString i18n(const QString &string); - /** - * @brief wrapper for ngettext function - */ - Q_INVOKABLE QString i18np(const QString &string1, const QString &string2, int count); -private: - QString m_pluginName; - QString m_domain; -}; diff --git a/src/lib/plugins/qml/qmlpluginloader.cpp b/src/lib/plugins/qml/qmlpluginloader.cpp index e036cdf86..eb4be1528 100644 --- a/src/lib/plugins/qml/qmlpluginloader.cpp +++ b/src/lib/plugins/qml/qmlpluginloader.cpp @@ -17,13 +17,12 @@ * ============================================================ */ #include "qmlpluginloader.h" #include "qmlengine.h" -#include -#include #include "../config.h" -#if HAVE_LIBINTL -#include "qml/api/i18n/qmli18n.h" -#endif +#include +#include + +#include QmlPluginLoader::QmlPluginLoader(const QString &name, const QString &path) { @@ -62,16 +61,10 @@ QmlPluginInterface *QmlPluginLoader::instance() const void QmlPluginLoader::initEngineAndComponent() { m_engine = new QmlEngine(); + KLocalizedContext *context = new KLocalizedContext(this); + context->setTranslationDomain(QSL("falkon_%1").arg(m_name)); + m_engine->rootContext()->setContextObject(context); m_component = new QQmlComponent(m_engine, QDir(m_path).filePath(QStringLiteral("main.qml"))); m_engine->setExtensionPath(m_path); m_engine->setExtensionName(m_name); -#if HAVE_LIBINTL - auto i18n = new QmlI18n(m_name); - m_engine->globalObject().setProperty(QSL("__falkon_i18n"), m_engine->newQObject(i18n)); - m_engine->evaluate(QSL("i18n = function (s) { return __falkon_i18n.i18n(s) };")); - m_engine->evaluate(QSL("i18np = function (s1, s2) { return __falkon_i18n.i18np(s1, s2) }")); -#else - m_engine->evaluate(QSL("i18n = function (s) { return s; };")); - m_engine->evaluate(QSL("i18np = function (s1, s2) { return s1; }")); -#endif } diff --git a/src/scripts/helloqml/Messages.sh b/src/scripts/helloqml/Messages.sh index bcb9da945..05a9350b3 100755 --- a/src/scripts/helloqml/Messages.sh +++ b/src/scripts/helloqml/Messages.sh @@ -1,11 +1,3 @@ #! /bin/sh -XGETTEXT_FLAGS_QML="\ ---copyright-holder=This_file_is_part_of_KDE \ ---msgid-bugs-address=http://bugs.kde.org \ ---from-code=UTF-8 \ --L javascript \ --ki18n:1 -ki18np:1,2 \ -" - -$XGETTEXT_PROGRAM $XGETTEXT_FLAGS_QML `find . -name '*.qml' -o -name '*.js'` -o $podir/falkon_helloqml.pot +$XGETTEXT `find . -name '*.js' -o -name '*.qml'` -o $podir/falkon_helloqml.pot