Support loading translations for Python extensions

remotes/origin/Falkon/3.0
David Rosca 8 years ago
parent c991df30f4
commit 332b7a8e0a
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
  1. 1
      src/scripts/CMakeLists.txt
  2. 9
      src/scripts/hellopython/hellopython.py
  3. 5
      src/scripts/hellopython/sidebar.py
  4. 29
      src/scripts/i18n.py

@ -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()

@ -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)

@ -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

@ -0,0 +1,29 @@
# ============================================================
# Falkon - Qt web browser
# Copyright (C) 2018 David Rosca <nowrep@gmail.com>
#
# 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 <http://www.gnu.org/licenses/>.
# ============================================================
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
Loading…
Cancel
Save