[gnome-clocks] Add i18n support
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-clocks] Add i18n support
- Date: Thu, 16 Aug 2012 12:19:44 +0000 (UTC)
commit f9a2bfd62c766f458e8391174566639be73cf34a
Author: Paolo Borelli <pborelli gnome org>
Date: Wed Aug 15 15:37:12 2012 +0200
Add i18n support
Add the gettext machinery and try to mark the translatables strings
with _()
https://bugzilla.gnome.org/show_bug.cgi?id=681883
gnome-clocks | 13 +++++
gnomeclocks/app.py | 15 ++++--
gnomeclocks/clocks.py | 26 +++++-----
gnomeclocks/timer.py | 11 ++--
gnomeclocks/utils.py | 8 +++
gnomeclocks/widgets.py | 24 +++++----
po/gnome-clocks.pot | 126 ++++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 190 insertions(+), 33 deletions(-)
---
diff --git a/gnome-clocks b/gnome-clocks
index d4d48d6..260c020 100755
--- a/gnome-clocks
+++ b/gnome-clocks
@@ -29,16 +29,29 @@ if os.path.exists("gnome-clocks.doap"):
ENV_PATHS = {
"GNOME_CLOCKS_DATA_PATH": "data/",
"GNOME_CLOCKS_IMAGE_PATH": "data/",
+ "GNOME_CLOCKS_LOCALE_PATH": "locale/",
}
else:
ENV_PATHS = {
"GNOME_CLOCKS_DATA_PATH": "/usr/share/gnome-clocks/",
"GNOME_CLOCKS_IMAGE_PATH": "/usr/share/gnome-clocks/pixmaps/",
+ "GNOME_CLOCKS_LOCALE_PATH": "/usr/share/locale/",
}
for var, path in ENV_PATHS.iteritems():
os.environ.setdefault(var, path)
+# Setup i18n support
+import locale
+import gettext
+
+from gnomeclocks.utils import Dirs
+
+locale_domain = "gnome-clocks"
+locale.setlocale(locale.LC_ALL,'')
+gettext.bindtextdomain(locale_domain, Dirs.get_locale_dir ())
+gettext.textdomain(locale_domain)
+
from gnomeclocks.app import ClocksApplication
if __name__ == "__main__":
diff --git a/gnomeclocks/app.py b/gnomeclocks/app.py
index dc4e34a..64740c5 100644
--- a/gnomeclocks/app.py
+++ b/gnomeclocks/app.py
@@ -20,14 +20,17 @@
import os
+from gettext import gettext as _
+
from gi.repository import Gtk, Gdk, GObject, Gio
+
from clocks import World, Alarm, Timer, Stopwatch
from utils import Dirs
class Window(Gtk.ApplicationWindow):
def __init__(self, app):
- Gtk.ApplicationWindow.__init__(self, title="Clocks", application=app, hide_titlebar_when_maximized=True)
+ Gtk.ApplicationWindow.__init__(self, title=_("Clocks"), application=app, hide_titlebar_when_maximized=True)
self.set_wmclass("Clocks", "Clocks")
@@ -95,11 +98,11 @@ class Window(Gtk.ApplicationWindow):
self.show()
def show_about(self):
- about = Gtk.AboutDialog(title="About GNOME Clocks")
- about.set_title("About Clocks")
+ about = Gtk.AboutDialog(title=_("About GNOME Clocks"))
+ about.set_title(_("About Clocks"))
about.set_program_name("GNOME Clocks")
about.set_copyright("(c) Collabora Ltd\n(c) Emily Gonyer\n(c) Eslam Mostafa")
- about.set_comments("Clocks is a clock application for the GNOME Desktop")
+ about.set_comments(_("Clocks is a clock application for the GNOME Desktop"))
about.set_authors(["Seif Lotfy, Emily Gonyer, Eslam Mostafa"])
about.connect("response", lambda w, r: about.destroy())
about.set_wrap_license("true")
@@ -291,8 +294,8 @@ class ClocksApplication(Gtk.Application):
menu = Gio.Menu()
- menu.append("About Clocks", "app.about")
- menu.append("Quit", "app.quit")
+ menu.append(_("About Clocks"), "app.about")
+ menu.append(_("Quit"), "app.quit")
self.set_app_menu(menu)
about_action = Gio.SimpleAction.new("about", None)
diff --git a/gnomeclocks/clocks.py b/gnomeclocks/clocks.py
index da4aca1..18e0367 100644
--- a/gnomeclocks/clocks.py
+++ b/gnomeclocks/clocks.py
@@ -18,6 +18,8 @@
Author: Seif Lotfy <seif lotfy collabora co uk>
"""
+from gettext import gettext as _
+
from gi.repository import Gtk, GObject, Gio, Gdk, Gst, Notify, cairo
from gi.repository.GdkPixbuf import Pixbuf
@@ -84,7 +86,7 @@ class Clock (Gtk.EventBox):
class World (Clock):
def __init__ (self):
- Clock.__init__ (self, "World", True)
+ Clock.__init__ (self, _("World"), True)
self.addButton = None
self.liststore = liststore = Gtk.ListStore(Pixbuf, str, GObject.TYPE_PYOBJECT)
@@ -182,7 +184,7 @@ class World (Clock):
class Alarm (Clock):
def __init__ (self):
- Clock.__init__ (self, "Alarm", True)
+ Clock.__init__ (self, _("Alarm"), True)
self.liststore = liststore = Gtk.ListStore(Pixbuf, str, GObject.TYPE_PYOBJECT)
self.iconview = iconview = Gtk.IconView.new()
@@ -252,7 +254,7 @@ class Stopwatch (Clock):
# Stopped: 2
def __init__ (self):
- Clock.__init__ (self, "Stopwatch")
+ Clock.__init__ (self, _("Stopwatch"))
vbox = Gtk.Box (orientation = Gtk.Orientation.VERTICAL)
self.add (vbox)
@@ -283,9 +285,9 @@ class Stopwatch (Clock):
hbox.pack_start (self.rightButton, False, False, 0)
hbox.pack_start (Gtk.Box(), True, False, 0)
- self.leftLabel.set_markup (STOPWATCH_BUTTON_MARKUP%("Start"))
+ self.leftLabel.set_markup(STOPWATCH_BUTTON_MARKUP % (_("Start")))
self.leftLabel.set_padding (6, 0)
- self.rightLabel.set_markup (STOPWATCH_BUTTON_MARKUP%("Lap"))
+ self.rightLabel.set_markup(STOPWATCH_BUTTON_MARKUP % (_("Lap")))
self.rightLabel.set_padding (6, 0)
center.pack_start (self.stopwatchLabel, False, False, 0)
@@ -310,15 +312,15 @@ class Stopwatch (Clock):
if self.state == 0 or self.state == 2:
self.state = 1
self.start()
- self.leftLabel.set_markup (STOPWATCH_BUTTON_MARKUP%("Stop"))
- self.rightLabel.set_markup (STOPWATCH_BUTTON_MARKUP%("Lap"))
+ self.leftLabel.set_markup(STOPWATCH_BUTTON_MARKUP % (_("Stop")))
+ self.rightLabel.set_markup(STOPWATCH_BUTTON_MARKUP % (_("Lap")))
self.leftButton.get_style_context ().add_class ("clocks-stop")
self.rightButton.set_sensitive(True)
elif self.state == 1:
self.state = 2
self.stop()
- self.leftLabel.set_markup (STOPWATCH_BUTTON_MARKUP%("Continue"))
- self.rightLabel.set_markup (STOPWATCH_BUTTON_MARKUP%("Reset"))
+ self.leftLabel.set_markup(STOPWATCH_BUTTON_MARKUP % (_("Continue")))
+ self.rightLabel.set_markup(STOPWATCH_BUTTON_MARKUP % (_("Reset")))
self.leftButton.get_style_context ().remove_class ("clocks-stop")
self.leftButton.get_style_context ().add_class ("clocks-start")
@@ -328,7 +330,7 @@ class Stopwatch (Clock):
if self.state == 2:
self.state = 0
self.time_diff = 0
- self.leftLabel.set_markup (STOPWATCH_BUTTON_MARKUP%("Start"))
+ self.leftLabel.set_markup(STOPWATCH_BUTTON_MARKUP % (_("Start")))
self.leftButton.get_style_context ().add_class ("clocks-start")
#self.rightButton.get_style_context ().add_class ("clocks-lap")
self.stopwatchLabel.set_markup (STOPWATCH_LABEL_MARKUP%(0,0))
@@ -366,7 +368,7 @@ class Timer (Clock):
#Paused: 2
def __init__ (self):
- Clock.__init__ (self, "Timer")
+ Clock.__init__ (self, _("Timer"))
self.state = 0
self.g_id = 0
#
@@ -399,7 +401,7 @@ class Timer (Clock):
def end_timer_screen(self):
#self.timer_screen.rightButton.get_style_context ().add_class ("clocks-lap")
- self.timer_screen.leftLabel.set_markup (TIMER_BUTTON_MARKUP%("Pause"))
+ self.timer_screen.leftLabel.set_markup(TIMER_BUTTON_MARKUP % (_("Pause")))
self.timerbox.remove(self.timer_screen)
self.show_timer_welcome_screen()
self.timer_welcome_screen.hours.set_value(0)
diff --git a/gnomeclocks/timer.py b/gnomeclocks/timer.py
index be885bc..a7b1631 100644
--- a/gnomeclocks/timer.py
+++ b/gnomeclocks/timer.py
@@ -17,6 +17,7 @@
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
"""
+from gettext import gettext as _
from gi.repository import Gtk, Gio, Gdk
@@ -138,9 +139,9 @@ class TimerScreen (Gtk.Box):
hbox.pack_start (Gtk.Box(), True, True, 24)
hbox.pack_start (self.rightButton, True, True, 0)
- self.leftLabel.set_markup (TIMER_BUTTON_MARKUP%("Pause"))
+ self.leftLabel.set_markup(TIMER_BUTTON_MARKUP % (_("Pause")))
self.leftLabel.set_padding (6, 0)
- self.rightLabel.set_markup (TIMER_BUTTON_MARKUP%("Reset"))
+ self.rightLabel.set_markup(TIMER_BUTTON_MARKUP % (_("Reset")))
self.rightLabel.set_padding (6, 0)
self.leftButton.connect('clicked', self._on_left_button_clicked)
@@ -157,13 +158,13 @@ class TimerScreen (Gtk.Box):
if self.timer.state == 1: #Pause
self.timer.state = 2
self.timer.pause()
- self.leftLabel.set_markup(TIMER_BUTTON_MARKUP%("Continue"))
+ self.leftLabel.set_markup(TIMER_BUTTON_MARKUP % (_("Continue")))
#self.leftButton.get_style_context ().remove_class ("clocks-stop")
self.leftButton.get_style_context ().add_class ("clocks-start")
elif self.timer.state == 2: #Continue
self.timer.state = 1
self.timer.cont()
- self.leftLabel.set_markup(TIMER_BUTTON_MARKUP%("Pause"))
+ self.leftLabel.set_markup(TIMER_BUTTON_MARKUP % (_("Pause")))
self.leftButton.get_style_context ().remove_class ("clocks-start")
#self.leftButton.get_style_context ().add_class ("clocks-lap")
@@ -198,7 +199,7 @@ class TimerWelcomeScreen (Gtk.Box):
self.startButton.set_size_request(200, -1)
self.startButton.get_style_context ().add_class ("clocks-start")
self.startLabel = Gtk.Label()
- self.startLabel.set_markup (TIMER_BUTTON_MARKUP%("Start"))
+ self.startLabel.set_markup(TIMER_BUTTON_MARKUP % (_("Start")))
self.startLabel.set_padding (6, 0)
self.startButton.add(self.startLabel)
self.startButton.connect('clicked', self._on_start_clicked)
diff --git a/gnomeclocks/utils.py b/gnomeclocks/utils.py
index ef92232..624910f 100644
--- a/gnomeclocks/utils.py
+++ b/gnomeclocks/utils.py
@@ -37,3 +37,11 @@ class Dirs:
except:
path = "../data"
return path
+
+ @staticmethod
+ def get_locale_dir():
+ try:
+ path = os.environ['GNOME_CLOCKS_LOCALE_PATH']
+ except:
+ path = "locale"
+ return path
diff --git a/gnomeclocks/widgets.py b/gnomeclocks/widgets.py
index dcd3380..027cf50 100644
--- a/gnomeclocks/widgets.py
+++ b/gnomeclocks/widgets.py
@@ -18,10 +18,14 @@
Author: Seif Lotfy <seif lotfy collabora co uk>
"""
+from gettext import gettext as _
+
from gi.repository import Gtk, Gdk, GdkPixbuf, GObject, Gio, PangoCairo, Pango, GWeather
+
from storage import Location
from alarm import AlarmItem
from utils import Dirs
+
import os
import cairo, time
@@ -32,7 +36,7 @@ class NewWorldClockDialog (Gtk.Dialog):
None, (GObject.TYPE_PYOBJECT,))}
def __init__ (self, parent):
- Gtk.Dialog.__init__(self, "Add New Clock", parent)
+ Gtk.Dialog.__init__(self, _("Add New Clock"), parent)
self.set_transient_for(parent)
self.set_modal(True)
self.set_border_width (9)
@@ -43,7 +47,7 @@ class NewWorldClockDialog (Gtk.Dialog):
area.pack_start(box, True, True, 9)
self.label = Gtk.Label()
- self.label.set_markup("Search for a city or a time zone...")
+ self.label.set_markup(_("Search for a city or a time zone..."))
self.label.set_alignment(0.0, 0.5)
world = GWeather.Location.new_world(True)
@@ -52,14 +56,14 @@ class NewWorldClockDialog (Gtk.Dialog):
self.clear_gicon = Gio.ThemedIcon.new_with_default_fallbacks('edit-clear-symbolic')
self.searchEntry.set_icon_from_gicon(Gtk.EntryIconPosition.SECONDARY, self.find_gicon)
#self.searchEntry.set_can_focus(False)
- self.searchEntry.set_placeholder_text("Search for a city or a time zone...")
+ self.searchEntry.set_placeholder_text(_("Search for a city or a time zone..."))
- header = Gtk.Label("Add New Clock")
- header.set_markup("<span size='x-large'><b>Add a New World Clock</b></span>")
+ header = Gtk.Label(_("Add New Clock"))
+ header.set_markup("<span size='x-large'><b>%s</b></span>" % (_("Add a New World Clock")))
btnBox = Gtk.Box()
- self.add_buttons("Cancel", 0, "Save", 1)
+ self.add_buttons(_("Cancel"), 0, _("Save"), 1)
widget = self.get_widget_for_response (1)
widget.set_sensitive (False)
@@ -408,11 +412,11 @@ class NewAlarmDialog (Gtk.Dialog):
table1.attach (points, 2, 3, 0, 1)
table1.attach (minuteselect, 3, 4, 0, 1)
- name = Gtk.Label ("Name")
+ name = Gtk.Label(_("Name"))
name.set_alignment(1.0, 0.5)
- repeat = Gtk.Label ("Repeat Every")
+ repeat = Gtk.Label(_("Repeat Every"))
repeat.set_alignment(1.0, 0.5)
- sound = Gtk.Label ("Sound")
+ sound = Gtk.Label(_("Sound"))
sound.set_alignment(1.0, 0.5)
table1.attach(name, 0, 1, 1, 2)
@@ -420,7 +424,7 @@ class NewAlarmDialog (Gtk.Dialog):
#table1.attach(sound, 0, 1, 3, 4)
self.entry = entry = Gtk.Entry ()
- entry.set_text("New Alarm")
+ entry.set_text(_("New Alarm"))
entry.set_editable (True)
if cf == "12h":
table1.attach(entry, 1, 5, 1, 2)
diff --git a/po/gnome-clocks.pot b/po/gnome-clocks.pot
new file mode 100644
index 0000000..7aeca74
--- /dev/null
+++ b/po/gnome-clocks.pot
@@ -0,0 +1,126 @@
+# 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: 2012-08-15 15:51+0200\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"
+
+#: ../gnomeclocks/widgets.py:39 ../gnomeclocks/widgets.py:61
+msgid "Add New Clock"
+msgstr ""
+
+#. self.searchEntry.set_can_focus(False)
+#: ../gnomeclocks/widgets.py:50 ../gnomeclocks/widgets.py:59
+msgid "Search for a city or a time zone..."
+msgstr ""
+
+#: ../gnomeclocks/widgets.py:62
+msgid "Add a New World Clock"
+msgstr ""
+
+#: ../gnomeclocks/widgets.py:66
+msgid "Cancel"
+msgstr ""
+
+#: ../gnomeclocks/widgets.py:66
+msgid "Save"
+msgstr ""
+
+#: ../gnomeclocks/widgets.py:415
+msgid "Name"
+msgstr ""
+
+#: ../gnomeclocks/widgets.py:417
+msgid "Repeat Every"
+msgstr ""
+
+#: ../gnomeclocks/widgets.py:419
+msgid "Sound"
+msgstr ""
+
+#: ../gnomeclocks/widgets.py:427
+msgid "New Alarm"
+msgstr ""
+
+#. self.timer_screen.rightButton.get_style_context ().add_class ("clocks-lap")
+#: ../gnomeclocks/timer.py:142 ../gnomeclocks/timer.py:167
+#: ../gnomeclocks/clocks.py:404
+msgid "Pause"
+msgstr ""
+
+#: ../gnomeclocks/timer.py:144 ../gnomeclocks/clocks.py:323
+msgid "Reset"
+msgstr ""
+
+#: ../gnomeclocks/timer.py:161 ../gnomeclocks/clocks.py:322
+msgid "Continue"
+msgstr ""
+
+#: ../gnomeclocks/timer.py:202 ../gnomeclocks/clocks.py:288
+#: ../gnomeclocks/clocks.py:333
+msgid "Start"
+msgstr ""
+
+#: ../data/gnome-clocks.desktop.in.h:1 ../gnomeclocks/app.py:33
+msgid "Clocks"
+msgstr ""
+
+#: ../data/gnome-clocks.desktop.in.h:2
+msgid "Gnome Clocks"
+msgstr ""
+
+#: ../data/gnome-clocks.desktop.in.h:3
+msgid "Clocks for world times, plus alarms, stopwatch and a timer"
+msgstr ""
+
+#: ../gnomeclocks/clocks.py:89
+msgid "World"
+msgstr ""
+
+#: ../gnomeclocks/clocks.py:187
+msgid "Alarm"
+msgstr ""
+
+#: ../gnomeclocks/clocks.py:257
+msgid "Stopwatch"
+msgstr ""
+
+#: ../gnomeclocks/clocks.py:290 ../gnomeclocks/clocks.py:316
+msgid "Lap"
+msgstr ""
+
+#: ../gnomeclocks/clocks.py:315
+msgid "Stop"
+msgstr ""
+
+#: ../gnomeclocks/clocks.py:371
+msgid "Timer"
+msgstr ""
+
+#: ../gnomeclocks/app.py:101
+msgid "About GNOME Clocks"
+msgstr ""
+
+#: ../gnomeclocks/app.py:102 ../gnomeclocks/app.py:297
+msgid "About Clocks"
+msgstr ""
+
+#: ../gnomeclocks/app.py:105
+msgid "Clocks is a clock application for the GNOME Desktop"
+msgstr ""
+
+#: ../gnomeclocks/app.py:298
+msgid "Quit"
+msgstr ""
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]