diff --git a/src/scripts/CMakeLists.txt b/src/scripts/CMakeLists.txt index c1c16cbff..4f9526c83 100644 --- a/src/scripts/CMakeLists.txt +++ b/src/scripts/CMakeLists.txt @@ -1,6 +1,7 @@ function(install_python_script name) if (ENABLE_PYTHON_PLUGINS) install(DIRECTORY ${name} DESTINATION "${FALKON_INSTALL_PLUGINDIR}/python") + install(FILES i18n.py DESTINATION "${FALKON_INSTALL_PLUGINDIR}/python/${name}") endif() endfunction() diff --git a/src/scripts/hellopython/hellopython.py b/src/scripts/hellopython/hellopython.py index fd2f6515b..1ab9f7cf0 100644 --- a/src/scripts/hellopython/hellopython.py +++ b/src/scripts/hellopython/hellopython.py @@ -18,6 +18,7 @@ import Falkon from PySide2 import QtCore, QtGui, QtWidgets from hellopython import sidebar, button +from hellopython.i18n import i18n class HelloPlugin(Falkon.PluginInterface, QtCore.QObject): buttons = {} @@ -62,19 +63,19 @@ class HelloPlugin(Falkon.PluginInterface, QtCore.QObject): if r.isContentEditable(): title += " on input" - menu.addAction("My first plugin action" + title, self.actionSlot) + menu.addAction(i18n("My first plugin action") + title, self.actionSlot) def mousePress(self, type, obj, event): print("mousePress {} {} {}".format(type, obj, event)) return False def actionSlot(self): - QtWidgets.QMessageBox.information(self.view, "Hello", "First plugin action works :-)") + QtWidgets.QMessageBox.information(self.view, i18n("Hello"), i18n("First plugin action works :-)")) def showSettings(self, parent): self.settings = QtWidgets.QDialog(parent) b = QtWidgets.QPushButton("Hello Python v0.0.1") - closeButton = QtWidgets.QPushButton("Close") + closeButton = QtWidgets.QPushButton(i18n("Close")) label = QtWidgets.QLabel() label.setPixmap(QtGui.QPixmap(":icons/other/about.svg")) @@ -84,7 +85,7 @@ class HelloPlugin(Falkon.PluginInterface, QtCore.QObject): l.addWidget(closeButton) self.settings.setAttribute(QtCore.Qt.WA_DeleteOnClose) - self.settings.setWindowTitle("Hello Python Settings") + self.settings.setWindowTitle(i18n("Hello Python Settings")) self.settings.setWindowIcon(QtGui.QIcon(":icons/falkon.svg")) closeButton.clicked.connect(self.settings.close) diff --git a/src/scripts/hellopython/sidebar.py b/src/scripts/hellopython/sidebar.py index 1af6e2e8a..e6986ba39 100644 --- a/src/scripts/hellopython/sidebar.py +++ b/src/scripts/hellopython/sidebar.py @@ -17,13 +17,14 @@ # ============================================================ import Falkon from PySide2 import QtGui, QtWidgets +from hellopython.i18n import i18n class HelloSidebar(Falkon.SideBarInterface): def title(self): - return "HelloPython Sidebar" + return i18n("Hello Python Sidebar") def createMenuAction(self): - act = QtWidgets.QAction("Hello Python Sidebar") + act = QtWidgets.QAction(i18n("Hello Python Sidebar")) act.setCheckable(True) return act diff --git a/src/scripts/i18n.py b/src/scripts/i18n.py new file mode 100644 index 000000000..f6f272a7e --- /dev/null +++ b/src/scripts/i18n.py @@ -0,0 +1,29 @@ +# ============================================================ +# Falkon - Qt web browser +# Copyright (C) 2018 David Rosca +# +# 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 . +# ============================================================ +import gettext +from PySide2 import QtCore + +locale = QtCore.QLocale.system() +languages = [ locale.name(), locale.bcp47Name() ] +i = locale.name().find('_') +if i > 0: languages.append(locale.name()[:i]) +localedir = QtCore.QStandardPaths.locate(QtCore.QStandardPaths.GenericDataLocation, 'locale', QtCore.QStandardPaths.LocateDirectory) + +t = gettext.translation('falkon_' + __package__, localedir, languages, fallback=True) +i18n = t.gettext +i18np = t.ngettext