add support for internationalization with gettext and updated setup script for .po format

pull/2/head
Hans P. Möller 4 years ago
parent b3bb1ca1a0
commit be1a29219c

6
debian/changelog vendored

@ -1,3 +1,9 @@
lubuntu-update-notifier (0.4dev) UNRELEASED; urgency=medium
* added internationalization support
-- Hans P Möller <hmollercl@lubuntu.me> Sat, 12 Sep 2020 13:59:25 -0300
lubuntu-update-notifier (0.3) groovy; urgency=medium
* Added affected packages info.

1
debian/control vendored

@ -4,6 +4,7 @@ Priority: optional
Maintainer: Hans P Möller <hmollercl@lubuntu.me>
Build-Depends: debhelper-compat (=13),
dh-python,
gettext,
python3-all,
python3-apt,
python3-setuptools

@ -23,6 +23,7 @@ import subprocess
from pathlib import Path
import apt_pkg
from argparse import ArgumentParser
import gettext
from PyQt5.QtWidgets import (QWidget, QApplication, QLabel, QPushButton,
QHBoxLayout, QVBoxLayout, QTreeWidget,
@ -45,7 +46,7 @@ class Dialog(QWidget):
try:
self.cache = apt_pkg.Cache()
except SystemError as e:
sys.stderr.write("Error: Opening the cache (%s)" % e)
sys.stderr.write(_("Error: Opening the cache (%s)") % e)
sys.exit(-1)
self.depcache = apt_pkg.DepCache(self.cache)
@ -60,7 +61,7 @@ class Dialog(QWidget):
self.tw = QTreeWidget()
self.tw.setColumnCount(1)
self.tw.setHeaderLabels(['Affected Packages'])
self.tw.setHeaderLabels([_('Affected Packages')])
self.tw.setHeaderHidden(True)
self.upgradeBtn = QPushButton("Upgrade")
@ -98,26 +99,28 @@ class Dialog(QWidget):
pkg_install.append(p.name)
elif self.depcache.marked_upgrade(p):
pkg_upgrade.append(p.name)
text = "There are upgrades available. Do you want to do a system"
text += " upgrade?\nThis will mean packages could be upgraded,"
text += " installed, or removed."
text = _("There are upgrades available. Do you want to do a system "
"upgrade?")
text += "\n"
text += _("This will mean packages could be upgraded, installed, or "
"removed.")
if len(pkg_delete) > 0:
toDelete = QTreeWidgetItem(['Remove'])
toDelete = QTreeWidgetItem([_('Remove')])
for p in pkg_delete:
td_child = QTreeWidgetItem([p])
toDelete.addChild(td_child)
toDelete.setIcon(0, QIcon.fromTheme("edit-delete"))
self.tw.addTopLevelItem(toDelete)
if len(pkg_install) > 0:
toInstall = QTreeWidgetItem(['Install'])
toInstall = QTreeWidgetItem([_('Install')])
for p in pkg_install:
td_child = QTreeWidgetItem([p])
toInstall.addChild(td_child)
toInstall.setIcon(0, QIcon.fromTheme("system-software-install"))
self.tw.addTopLevelItem(toInstall)
if len(pkg_upgrade) > 0:
toUpgrade = QTreeWidgetItem(['Upgrade'])
toUpgrade = QTreeWidgetItem([_('Upgrade')])
for p in pkg_upgrade:
td_child = QTreeWidgetItem([p])
toUpgrade.addChild(td_child)
@ -126,10 +129,11 @@ class Dialog(QWidget):
if self.reboot_required:
if text == "":
text = "Reboot is needed"
text = _("Reboot required")
self.upgradeBtn.setVisible(False)
else:
text = text + "\nReboot is needed"
text += "\n"
text += _("Reboot required")
self.label.setText(text)
@ -148,7 +152,7 @@ class Dialog(QWidget):
def call_upgrade(self):
''' starts upgrade process '''
self.label.setText("Upgrading...")
self.label.setText(_("Upgrading..."))
# TODO maybe open another thread so notifier won't freeze
if self.upg_path == "terminal":
# cmd = ['qterminal', '-e', 'sudo', 'apt', 'dist-upgrade']
@ -163,11 +167,11 @@ class Dialog(QWidget):
process.wait()
if self.upg_path == "terminal":
text = "Upgrade finished"
text = _("Upgrade finished")
reboot_required_path = Path("/var/run/reboot-required")
if reboot_required_path.exists():
text = text + "\n" + "Restart required"
text += "\n" + _("Reboot required")
self.label.setText(text)
self.closeBtn.setVisible(True)
self.closeBtn.setEnabled(True)
@ -195,21 +199,27 @@ def main(args, upgrades, security_upgrades, reboot_required, upg_path):
if __name__ == "__main__":
localesApp ="lubuntu-update-notifier"
localesDir ="/usr/share/locale"
gettext.bindtextdomain(localesApp, localesDir)
gettext.textdomain(localesApp)
_ = gettext.gettext
parser = ArgumentParser()
parser.add_argument("-p",
"--upgrader-sw",
dest="upg_path",
help="Define software/app to open for upgrade",
help=_("Define software/app to open for upgrade"),
metavar="APP")
parser.add_argument("-u",
"--upgrades",
dest="upgrades",
help="How many upgrades are available",
help=_("How many upgrades are available"),
metavar="APP")
parser.add_argument("-s",
"--security-upg",
dest="security_upgrades",
help="How many security upgrades are available",
help=_("How many security upgrades are available"),
metavar="APP")
options = parser.parse_args()

@ -22,7 +22,7 @@
import sys
import os
from pathlib import Path
# from optparse import OptionParser
import gettext
from argparse import ArgumentParser
from PyQt5.QtWidgets import (QWidget, QApplication, QLabel, QPushButton,
QHBoxLayout, QVBoxLayout, QProgressBar,
@ -126,7 +126,7 @@ class DialogUpg(QWidget):
'''upgrade progressbar during update'''
self.progressBar.setVisible(True)
self.progressBar.setValue(progress)
self.label.setText("Updating cache...")
self.label.setText(_("Updating cache..."))
def update_progress_download(self, transaction, uri, status, short_desc,
total_size, current_size, msg):
@ -183,11 +183,11 @@ class DialogUpg(QWidget):
'''print update detail info'''
if total_items > 0:
self.plainTextEdit.setVisible(True)
if self.detailText != "Fetching " + str(
current_items) + " of " + str(total_items):
if self.detailText != _("Fetching") + str(
current_items) + " " + _("of") + " " + str(total_items):
self.detailText = (
"Fetching " + str(current_items) + " of "
+ str(total_items)
_("Fetching") + " " + str(current_items) + " " + _("of") +
" " + str(total_items)
)
self.label.setText(self.detailText + "\n" + self.downloadText)
@ -196,11 +196,11 @@ class DialogUpg(QWidget):
'''print upgrade detail info'''
if total_items > 0:
self.plainTextEdit.setVisible(True)
if self.detailText != "Downloaded " + str(
current_items) + " of " + str(total_items):
if self.detailText != _("Downloaded") + " " + str(
current_items) + " " + _("of") + " " + str(total_items):
self.detailText = (
"Downloaded " + str(current_items) + " of "
+ str(total_items)
_("Downloaded") + " " + str(current_items) + " " +
_("of") + " " + str(total_items)
)
self.label.setText(self.detailText + "\n" + self.downloadText)
@ -211,16 +211,16 @@ class DialogUpg(QWidget):
error_desc = get_error_description_from_enum(
transaction.error.code)
text = "Upgrade finished"
text = _("Upgrade finished")
reboot_required_path = Path("/var/run/reboot-required")
if reboot_required_path.exists():
text = text + "\n" + "Restart required"
text = text + "\n" + _("Reboot required")
self.progressBar.setVisible(False)
if len(self.errors) > 0:
text = text + "\n With some Errors"
self.plainTextEdit.appendPlainText("Error Resume:\n")
text += "\n" + _("With some Errors")
self.plainTextEdit.appendPlainText(_("Error Resume:") + "\n")
for error in self.errors:
self.plainTextEdit.setEnabled(False)
self.plainTextEdit.insertPlainText(error + "\n")
@ -271,7 +271,7 @@ class DialogUpg(QWidget):
def update_finish(self, transaction, exit_state):
'''when update finish'''
self.label.setText("Update Cache Finished")
self.label.setText(_("Update Cache Finished"))
if exit_state == EXIT_FAILED:
error_string = get_error_string_from_enum(transaction.error.code)
error_desc = get_error_description_from_enum(
@ -366,8 +366,8 @@ def main(args, options):
# Check for root permissions
if os.geteuid() != 0:
text = "Please run this software with administrative rights."
text += "To do so, run this program with lxqt-sudo."
text = _("Please run this software with administrative rights."
"To do so, run this program with lxqt-sudo.")
title = "Need administrative powers"
QMessageBox.critical(None, title, text)
sys.exit()
@ -376,18 +376,24 @@ def main(args, options):
if __name__ == "__main__":
localesApp ="lubuntu-update-notifier"
localesDir ="/usr/share/locale"
gettext.bindtextdomain(localesApp, localesDir)
gettext.textdomain(localesApp)
_ = gettext.gettext
# check arguments
parser = ArgumentParser()
parser.add_argument("-c",
"--cache-update",
action="store_true",
dest="cacheUpdate",
help="Update Cache Before Upgrade")
help=_("Update Cache Before Upgrade"))
parser.add_argument("-f",
"--full-upgrade",
action="store_true",
dest="fullUpgrade",
help="Full upgrade same as dist-upgrade")
help=_("Full upgrade same as dist-upgrade"))
parser.add_argument('--version',
action='version',
version='%(prog)s 0.1')

@ -0,0 +1,114 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-09-12 13:43-0300\n"
"PO-Revision-Date: 2020-09-12 13:49-0300\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.3\n"
"Last-Translator: \n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"Language: es\n"
#: lubuntu-upgrader:129
msgid "Updating cache..."
msgstr "Actualizando cache..."
#: lubuntu-upgrader:186 lubuntu-upgrader:189
msgid "Fetching"
msgstr "Atrayendo"
#: lubuntu-upgrader:187 lubuntu-upgrader:189 lubuntu-upgrader:200
#: lubuntu-upgrader:203
msgid "of"
msgstr "de"
#: lubuntu-upgrader:199 lubuntu-upgrader:202
msgid "Downloaded"
msgstr "Descargado"
#: lubuntu-upgrader:214 lubuntu-notifier.py:170
msgid "Upgrade finished"
msgstr "Actualización completada"
#: lubuntu-upgrader:218 lubuntu-notifier.py:132 lubuntu-notifier.py:136
#: lubuntu-notifier.py:174
msgid "Reboot required"
msgstr "Requiere reinicio"
#: lubuntu-upgrader:222
msgid "With some Errors"
msgstr "Con algunos Errores"
#: lubuntu-upgrader:223
msgid "Error Resume:"
msgstr "Resumen de Errores:"
#: lubuntu-upgrader:274
msgid "Update Cache Finished"
msgstr "Actualización de Cache Terminada"
#: lubuntu-upgrader:369
msgid ""
"Please run this software with administrative rights.To do so, run this "
"program with lxqt-sudo."
msgstr ""
"Por favor corre este software como administrador. Para hacerlo "
"ejecútarlo con lxqt-sudo."
#: lubuntu-upgrader:391
msgid "Update Cache Before Upgrade"
msgstr "Actualiza el Cache antes de la Actualización"
#: lubuntu-upgrader:396
msgid "Full upgrade same as dist-upgrade"
msgstr "\"Full upgrade\" lo mismo que \"dist-upgrade\""
#: lubuntu-notifier.py:64
msgid "Affected Packages"
msgstr "Paquetes adectados"
#: lubuntu-notifier.py:102
msgid "There are upgrades available. Do you want to do a system upgrade?"
msgstr ""
"Hay actualizaciones disponibles ¿Quiere hacer una actualización del sistema?"
#: lubuntu-notifier.py:105
msgid "This will mean packages could be upgraded, installed, or removed."
msgstr "Esto implica que paquetes pueden actualizarse, instalarse o removerse"
#: lubuntu-notifier.py:109
msgid "Remove"
msgstr "Quitar"
#: lubuntu-notifier.py:116
msgid "Install"
msgstr "Instalar"
#: lubuntu-notifier.py:123
msgid "Upgrade"
msgstr "Actualizar"
#: lubuntu-notifier.py:155
msgid "Upgrading..."
msgstr "Actualizando..."
#: lubuntu-notifier.py:212
msgid "Define software/app to open for upgrade"
msgstr "Define el software o app para actualizar"
#: lubuntu-notifier.py:217
msgid "How many upgrades are available"
msgstr "Cuántas actualizaciones hay disponibles"
#: lubuntu-notifier.py:222
msgid "How many security upgrades are available"
msgstr "Cuántas actualizaciones de seguridad hay disponibles"

@ -0,0 +1,110 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-09-12 13:43-0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: lubuntu-upgrader:129
msgid "Updating cache..."
msgstr ""
#: lubuntu-upgrader:186 lubuntu-upgrader:189
msgid "Fetching"
msgstr ""
#: lubuntu-upgrader:187 lubuntu-upgrader:189 lubuntu-upgrader:200
#: lubuntu-upgrader:203
msgid "of"
msgstr ""
#: lubuntu-upgrader:199 lubuntu-upgrader:202
msgid "Downloaded"
msgstr ""
#: lubuntu-upgrader:214 lubuntu-notifier.py:170
msgid "Upgrade finished"
msgstr ""
#: lubuntu-upgrader:218 lubuntu-notifier.py:132 lubuntu-notifier.py:136
#: lubuntu-notifier.py:174
msgid "Reboot required"
msgstr ""
#: lubuntu-upgrader:222
msgid "With some Errors"
msgstr ""
#: lubuntu-upgrader:223
msgid "Error Resume:"
msgstr ""
#: lubuntu-upgrader:274
msgid "Update Cache Finished"
msgstr ""
#: lubuntu-upgrader:369
msgid ""
"Please run this software with administrative rights.To do so, run this "
"program with lxqt-sudo."
msgstr ""
#: lubuntu-upgrader:391
msgid "Update Cache Before Upgrade"
msgstr ""
#: lubuntu-upgrader:396
msgid "Full upgrade same as dist-upgrade"
msgstr ""
#: lubuntu-notifier.py:64
msgid "Affected Packages"
msgstr ""
#: lubuntu-notifier.py:102
msgid "There are upgrades available. Do you want to do a system upgrade?"
msgstr ""
#: lubuntu-notifier.py:105
msgid "This will mean packages could be upgraded, installed, or removed."
msgstr ""
#: lubuntu-notifier.py:109
msgid "Remove"
msgstr ""
#: lubuntu-notifier.py:116
msgid "Install"
msgstr ""
#: lubuntu-notifier.py:123
msgid "Upgrade"
msgstr ""
#: lubuntu-notifier.py:155
msgid "Upgrading..."
msgstr ""
#: lubuntu-notifier.py:212
msgid "Define software/app to open for upgrade"
msgstr ""
#: lubuntu-notifier.py:217
msgid "How many upgrades are available"
msgstr ""
#: lubuntu-notifier.py:222
msgid "How many security upgrades are available"
msgstr ""

@ -17,13 +17,48 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from setuptools import setup
import subprocess
import os
from distutils.command.clean import clean
class MyClean(clean):
def run(self):
# Execute the classic clean command
super().run()
# Custom clean
print("Removing translations")
subprocess.run(['rm', '-rf', 'translations'])
def add_mo_files(data_files):
app_name = 'lubuntu-update-notifier'
mo = ''
subprocess.run(['mkdir', 'translations/'])
for f in os.listdir('po'):
loc, ext = os.path.splitext(f)
if ext == '.po':
mo = app_name + '.mo'
subprocess.run(['mkdir', 'translations/' + loc])
subprocess.run(['msgfmt', '-o', 'translations/' + loc + '/' + mo,
'po/' + f], check=True)
data_files.append(('share/locale/' + loc + '/LC_MESSAGES/',
['translations/' + loc + '/' + mo]))
return data_files
data_files=[('libexec/lubuntu-update-notifier/',
['lubuntu-upg-notifier.sh', 'lubuntu-notifier.py']),
('share/applications', ['data/upg-apply.desktop'])]
setup(
name="lubuntu-update-notifier",
version="0.1",
version="0.4dev",
packages=['lubuntu-update-notifier'],
scripts=['lubuntu-upgrader'],
data_files=[('libexec/lubuntu-update-notifier/',
['lubuntu-upg-notifier.sh', 'lubuntu-notifier.py']),
('share/applications', ['data/upg-apply.desktop'])]
data_files=add_mo_files(data_files),
cmdclass={'clean': MyClean}
)

@ -0,0 +1,2 @@
xgettext lubuntu-upgrader lubuntu-notifier.py --language=Python
mv messages.po po/lubuntu-update-notifier.pot
Loading…
Cancel
Save