Skip to content

Commit cecabbf

Browse files
committed
Setup translation using gettext and update about dialog
1 parent 43f6fcf commit cecabbf

File tree

7 files changed

+188
-103
lines changed

7 files changed

+188
-103
lines changed

usr/lib/battery-monitor/AboutWindow.py

+43-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#!/usr/bin/env python3
22

33
# third-party library
4+
import gettext
45
import gi
6+
import locale
7+
58
gi.require_version('Gtk', '3.0')
69
from gi.repository import Gtk
710
from gi.repository import GdkPixbuf
@@ -10,6 +13,14 @@
1013
from config import ICONS
1114

1215

16+
# i18n
17+
APP = 'battery-monitor'
18+
LOCALE_DIR = "/usr/share/locale"
19+
locale.bindtextdomain(APP, LOCALE_DIR)
20+
gettext.bindtextdomain(APP, LOCALE_DIR)
21+
gettext.textdomain(APP)
22+
_ = gettext.gettext
23+
1324

1425
class AboutWindow():
1526
"""GUI class for About Window.
@@ -19,29 +30,51 @@ class AboutWindow():
1930

2031
def __init__(self):
2132
authors = [
33+
'Himadri Sekhar Basu <https://hsbasu.github.io>',
2234
'Maksudur Rahman Maateen <https://maateen.me/>',
2335
'Safwan Rahman <https://github.com/safwanrahman>',
2436
'Abdelhak BOUGOUFFA <https://abougouffa.github.io/>'
2537
]
38+
copyrights = "Copyright \xa9 2016-2018 Maksudur Rahman Maateen\n \
39+
Copyright \xa9 2021 Himadri Sekhar Basu"
2640
documenters = [
27-
'Maksudur Rahman Maateen <https://maateen.me/>',
41+
'Maksudur Rahman Maateen <https://maateen.me/>'
42+
]
43+
mainatainers = [
44+
'Himadri Sekhar Basu <https://hsbasu.github.io>'
2845
]
2946

3047
# initiaing about dialog and params
3148
self.about_dialog = Gtk.AboutDialog()
32-
self.about_dialog.set_program_name('Battery Monitor')
33-
self.about_dialog.set_version("0.6")
34-
self.about_dialog.set_copyright('Copyright \xa9 2016-2018 Maksudur Rahman Maateen')
49+
50+
self.about_dialog.set_icon_name("battery-monitor")
51+
self.about_dialog.set_title(_("About"))
52+
53+
self.about_dialog.set_logo_icon_name("battery-monitor")
54+
self.about_dialog.set_program_name(_('Battery Monitor'))
55+
self.about_dialog.set_version("__DEB_VERSION__")
56+
3557
self.about_dialog.set_website_label('Official Website')
3658
self.about_dialog.set_website('https://hsbasu.github.io/battery-monitor/')
37-
self.about_dialog.set_comments('Battery Monitor is a utility tool developed on Python3 and PyGtk3. It will notify the user about charging, discharging, not charging and critically low battery state of the battery on Linux (surely if the battery is present).')
38-
self.about_dialog.set_license_type (Gtk.License.GPL_3_0,)
39-
self.about_dialog.set_default_icon_from_file(ICONS['app'])
40-
self.about_dialog.set_logo(GdkPixbuf.Pixbuf.new_from_file_at_size(ICONS['app'], 64, 64))
59+
self.about_dialog.set_comments(_('Battery Monitor is a utility tool developed on Python3 and PyGtk3. It will notify the user about charging, discharging, not charging and critically low battery state of the battery on Linux (surely if the battery is present).'))
60+
self.about_dialog.set_copyright(copyrights)
61+
4162
self.about_dialog.set_authors(authors)
4263
self.about_dialog.set_documenters(documenters)
43-
self.about_dialog.add_credit_section('AUR maintained by', ['Yochanan Marqos <https://github.com/yochananmarqos>'])
44-
self.about_dialog.set_title('About Battery Monitor')
64+
# self.about_dialog.add_credit_section('AUR maintained by', ['Yochanan Marqos <https://github.com/yochananmarqos>'])
65+
self.about_dialog.add_credit_section(_('Maintainer'), mainatainers)
66+
67+
try:
68+
h = open('/usr/share/common-licenses/GPL', encoding="utf-8")
69+
s = h.readlines()
70+
gpl = ""
71+
for line in s:
72+
gpl += line
73+
h.close()
74+
self.about_dialog.set_license(gpl)
75+
except Exception as e:
76+
print (e)
77+
4578
self.about_dialog.connect('response', self.__close)
4679

4780
def show(self):
+31-20
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#!/usr/bin/env python3
22

33
# standard library
4-
import subprocess
5-
import time
4+
import gettext
5+
import locale
66
import platform
7+
import subprocess
78
from threading import Thread
9+
import time
810

911
# third-party library
1012
import gi
@@ -21,49 +23,58 @@
2123
from Notification import Notification
2224
from SettingsWindow import SettingsWindow
2325

26+
27+
# i18n
28+
APP = 'battery-monitor'
29+
LOCALE_DIR = "/usr/share/locale"
30+
locale.bindtextdomain(APP, LOCALE_DIR)
31+
gettext.bindtextdomain(APP, LOCALE_DIR)
32+
gettext.textdomain(APP)
33+
_ = gettext.gettext
34+
2435
class AppIndicator:
2536
"""Class for system tray icon.
26-
37+
2738
This class will show Battery Monitor icon in system tray.
2839
"""
2940
if platform.python_version() >= '3.6':
3041
TEST_MODE: bool
31-
42+
3243
def __init__(self, TEST_MODE: bool = False):
3344
self.indicator = AppIndicator3.Indicator.new(APPINDICATOR_ID, ICONS['app'], AppIndicator3.IndicatorCategory.SYSTEM_SERVICES)
34-
self.indicator.set_title('Battery Monitor')
45+
self.indicator.set_title(_('Battery Monitor'))
3546
self.indicator.set_status(AppIndicator3.IndicatorStatus.ACTIVE)
36-
47+
3748
# create menu
3849
self.indicator.set_menu(self.__create_menu())
39-
50+
4051
# run the daemon
4152
self.daemon = Thread(target=self.__run_daemon, args=(TEST_MODE,))
4253
self.daemon.setDaemon(True)
4354
self.daemon.start()
44-
55+
4556
def __about_window(self, *args):
4657
about_window = AboutWindow()
4758
about_window.show()
48-
59+
4960
def __create_menu(self):
5061
menu = Gtk.Menu()
51-
52-
item_settings = Gtk.MenuItem('Settings')
62+
63+
item_settings = Gtk.MenuItem(_('Settings'))
5364
item_settings.connect("activate", self.__settings_window)
5465
menu.append(item_settings)
55-
56-
item_about = Gtk.MenuItem('About')
66+
67+
item_about = Gtk.MenuItem(_('About'))
5768
item_about.connect("activate", self.__about_window)
5869
menu.append(item_about)
59-
60-
item_quit = Gtk.MenuItem('Quit')
70+
71+
item_quit = Gtk.MenuItem(_('Quit'))
6172
item_quit.connect("activate", self.__quit)
6273
menu.append(item_quit)
6374
menu.show_all()
64-
75+
6576
return menu
66-
77+
6778
def __run_daemon(self, TEST_MODE: bool = False):
6879
# initiaing BatteryMonitor
6980
try:
@@ -74,20 +85,20 @@ def __run_daemon(self, TEST_MODE: bool = False):
7485
time.sleep(5)
7586
del notification
7687
self.__quit()
77-
88+
7889
# initiaing Notification
7990
notification = Notification("success")
8091
notification.show_specific_notifications(monitor)
8192
while True:
8293
if monitor.is_updated():
8394
notification.show_specific_notifications(monitor)
8495
time.sleep(5)
85-
96+
8697
def __settings_window(self, *args):
8798
settings = SettingsWindow()
8899
settings.connect('destroy', Gtk.main_quit)
89100
settings.show_all()
90101
Gtk.main()
91-
102+
92103
def __quit(self, *args):
93104
Gtk.main_quit()

usr/lib/battery-monitor/BatteryMonitor.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
#!/usr/bin/env python3
22

33
# standard library
4+
import gettext
5+
import locale
6+
import platform
47
import random
58
import subprocess
6-
import platform
79
from typing import Dict
810

911
# imports from current project
1012
from config import TEST_CASES
1113

1214

15+
# i18n
16+
APP = 'battery-monitor'
17+
LOCALE_DIR = "/usr/share/locale"
18+
locale.bindtextdomain(APP, LOCALE_DIR)
19+
gettext.bindtextdomain(APP, LOCALE_DIR)
20+
gettext.textdomain(APP)
21+
_ = gettext.gettext
22+
1323
class BatteryMonitor:
1424
if platform.python_version() >= '3.6':
1525
raw_battery_info: str
@@ -48,10 +58,9 @@ def is_updated(self):
4858
def get_processed_battery_info(self):
4959
in_list = (self.raw_battery_info.decode("utf-8", "strict").lower().strip('\n')
5060
.split(": ", 1)[1].split(", "))
51-
print(in_list)
52-
self.processed_battery_info["state"] = in_list[0]
53-
self.processed_battery_info["percentage"] = in_list[1]
5461
try:
62+
self.processed_battery_info["state"] = in_list[0]
63+
self.processed_battery_info["percentage"] = in_list[1]
5564
self.processed_battery_info["remaining"] = in_list[2]
5665
except IndexError:
5766
pass

usr/lib/battery-monitor/Notification.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
# standard library
44
import configparser
5+
import gettext
6+
import locale
57
import os
68
import platform
79
import time
@@ -19,6 +21,15 @@
1921
from config import MESSAGES
2022

2123

24+
# i18n
25+
APP = 'battery-monitor'
26+
LOCALE_DIR = "/usr/share/locale"
27+
locale.bindtextdomain(APP, LOCALE_DIR)
28+
gettext.bindtextdomain(APP, LOCALE_DIR)
29+
gettext.textdomain(APP)
30+
_ = gettext.gettext
31+
32+
2233
class Notification:
2334
"""Triggers notification on battery state changes.
2435
@@ -37,7 +48,7 @@ def __init__(self, type: str, TEST_MODE: bool = False) -> None:
3748
self.load_config()
3849

3950
# initiating notification
40-
Notify.init("Battery Monitor")
51+
Notify.init(_("Battery Monitor"))
4152
message = MESSAGES[type]
4253
head = message[0]
4354
body = message[1]

0 commit comments

Comments
 (0)