Add i18n which allow translations
Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
This commit is contained in:
parent
ae01a4de54
commit
846da6c17f
11
autoZoomer/Messages.sh
Normal file
11
autoZoomer/Messages.sh
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
|
||||||
|
XGETTEXT_FLAGS_PYTHON="\
|
||||||
|
--copyright-holder=This_file_is_part_of_KDE \
|
||||||
|
--msgid-bugs-address=http://bugs.kde.org \
|
||||||
|
--from-code=UTF-8 \
|
||||||
|
-L Python \
|
||||||
|
-ki18n:1 -ki18np:1,2 \
|
||||||
|
"
|
||||||
|
|
||||||
|
$XGETTEXT_PROGRAM $XGETTEXT_FLAGS_PYTHON `find . -name '*.py'` -o $podir/autoZoomer.pot
|
@ -19,6 +19,7 @@
|
|||||||
import Falkon
|
import Falkon
|
||||||
import os
|
import os
|
||||||
from PySide2 import QtGui
|
from PySide2 import QtGui
|
||||||
|
from autoZoomer.i18n import i18n
|
||||||
|
|
||||||
|
|
||||||
class AutoZoomerButton(Falkon.AbstractButtonInterface):
|
class AutoZoomerButton(Falkon.AbstractButtonInterface):
|
||||||
@ -29,8 +30,8 @@ class AutoZoomerButton(Falkon.AbstractButtonInterface):
|
|||||||
self.manager = manager
|
self.manager = manager
|
||||||
|
|
||||||
self.setIcon(QtGui.QIcon(os.path.join(os.path.dirname(__file__), "icon.svg")))
|
self.setIcon(QtGui.QIcon(os.path.join(os.path.dirname(__file__), "icon.svg")))
|
||||||
self.setTitle("Auto Zoomer")
|
self.setTitle(i18n("Auto Zoomer"))
|
||||||
self.setToolTip("Save current zoom level")
|
self.setToolTip(i18n("Save current zoom level"))
|
||||||
|
|
||||||
self.clicked.connect(self.onClicked)
|
self.clicked.connect(self.onClicked)
|
||||||
|
|
||||||
|
40
autoZoomer/i18n.py
Normal file
40
autoZoomer/i18n.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
# ============================================================
|
||||||
|
# Falkon - Qt web browser
|
||||||
|
# Copyright (C) 2018 David Rosca <nowrep@gmail.com>
|
||||||
|
# Copyright (C) 2019 Juraj Oravec <sgd.orava@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
|
||||||
|
import os
|
||||||
|
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,
|
||||||
|
os.path.join(os.path.dirname(__file__), "locale"),
|
||||||
|
QtCore.QStandardPaths.LocateDirectory
|
||||||
|
)
|
||||||
|
|
||||||
|
t = gettext.translation('falkon_' + __package__, localedir, languages, fallback=True)
|
||||||
|
i18n = t.gettext
|
||||||
|
i18np = t.ngettext
|
@ -19,6 +19,7 @@
|
|||||||
import os
|
import os
|
||||||
from PySide2 import QtCore, QtWidgets, QtUiTools
|
from PySide2 import QtCore, QtWidgets, QtUiTools
|
||||||
from autoZoomer.listItem import ListItem
|
from autoZoomer.listItem import ListItem
|
||||||
|
from autoZoomer.i18n import i18n
|
||||||
|
|
||||||
|
|
||||||
class SettingsDialog(QtWidgets.QDialog):
|
class SettingsDialog(QtWidgets.QDialog):
|
||||||
@ -45,6 +46,8 @@ class SettingsDialog(QtWidgets.QDialog):
|
|||||||
layout.addWidget(self.ui)
|
layout.addWidget(self.ui)
|
||||||
self.setLayout(layout)
|
self.setLayout(layout)
|
||||||
|
|
||||||
|
self.translations()
|
||||||
|
|
||||||
self.ui.checkBoxEnableAutoZoomer.setChecked(self.config["active"])
|
self.ui.checkBoxEnableAutoZoomer.setChecked(self.config["active"])
|
||||||
self.ui.checkBoxDefaultZoom.setChecked(self.config["defaultZoom"])
|
self.ui.checkBoxDefaultZoom.setChecked(self.config["defaultZoom"])
|
||||||
|
|
||||||
@ -64,6 +67,13 @@ class SettingsDialog(QtWidgets.QDialog):
|
|||||||
self.ui.buttonBoxConfirm.accepted.connect(self.accept)
|
self.ui.buttonBoxConfirm.accepted.connect(self.accept)
|
||||||
self.ui.buttonBoxConfirm.rejected.connect(self.reject)
|
self.ui.buttonBoxConfirm.rejected.connect(self.reject)
|
||||||
|
|
||||||
|
def translations(self):
|
||||||
|
self.setWindowTitle(i18n("Auto Zoomer Settings"))
|
||||||
|
self.ui.pushButtonAdd.setText(i18n("Add"))
|
||||||
|
self.ui.pushButtonRemove.setText(i18n("Remove"))
|
||||||
|
self.ui.checkBoxEnableAutoZoomer.setText(i18n("Enable Auto Zoomer"))
|
||||||
|
self.ui.checkBoxDefaultZoom.setText(i18n("On unknown host zoom to default zoom level"))
|
||||||
|
|
||||||
def addListItem(self, host, zoom=6, active=True):
|
def addListItem(self, host, zoom=6, active=True):
|
||||||
if not host:
|
if not host:
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user