[gnome-games] sudoku: Make play duration strings more translatable (Bug #628161)
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] sudoku: Make play duration strings more translatable (Bug #628161)
- Date: Fri, 22 Oct 2010 06:09:11 +0000 (UTC)
commit 183f113a9e7a87067ad3aa7de9c40a4aa893bc9a
Author: Robert Ancell <robert ancell canonical com>
Date: Fri Oct 22 16:55:08 2010 +1100
sudoku: Make play duration strings more translatable (Bug #628161)
gnome-sudoku/src/lib/game_selector.py | 13 +++++--
gnome-sudoku/src/lib/main.py | 22 +++++++++---
gnome-sudoku/src/lib/timer.py | 63 ++------------------------------
3 files changed, 31 insertions(+), 67 deletions(-)
---
diff --git a/gnome-sudoku/src/lib/game_selector.py b/gnome-sudoku/src/lib/game_selector.py
index 30ff747..99e551e 100644
--- a/gnome-sudoku/src/lib/game_selector.py
+++ b/gnome-sudoku/src/lib/game_selector.py
@@ -6,7 +6,6 @@ import sudoku_thumber
from gettext import gettext as _
from gettext import ngettext
import time
-from timer import format_time
import defaults
from simple_debug import simple_debug
from colors import color_hex_to_float
@@ -185,8 +184,16 @@ class NewOrSavedGameSelector:
sdifficulty = sr.difficulty()
lastPlayedText = self.format_friendly_date(g['saved_at'])
levelText = _("%(level)s puzzle") % {'level': sdifficulty.value_string()}
- durationText = _("Played for %(duration)s") % {
- 'duration': format_time(g['timer.active_time'], round_at = 15, friendly = True)}
+ tim = g['timer.active_time']
+ if tim >= 3600.0:
+ hours = int(tim / 3600)
+ durationText = ngettext("Played for %d hour", "Played for %d hours", hours) % hours
+ elif tim >= 60.0:
+ minutes = int(tim / 60)
+ durationText = ngettext("Played for %d minute", "Played for %d minutes", minutes) % minutes
+ else:
+ seconds = int(tim)
+ durationText = ngettext("Played for %d second", "Played for %d seconds", seconds) % seconds
desc = "<b><i>%s</i></b>\n<span size='small'><i>%s</i>\n<i>%s.</i></span>" % (
levelText,
lastPlayedText,
diff --git a/gnome-sudoku/src/lib/main.py b/gnome-sudoku/src/lib/main.py
index e81321a..d0860aa 100644
--- a/gnome-sudoku/src/lib/main.py
+++ b/gnome-sudoku/src/lib/main.py
@@ -392,12 +392,24 @@ class UI (gconf_wrapper.GConfWrapper):
self.gconf['difficulty'] = self.gconf['difficulty'] + 0.1
self.timer.finish_timing()
self.sudoku_tracker.finish_game(self)
- if self.timer.active_time != self.timer.total_time:
- sublabel = _("You completed the puzzle in %(totalTime)s (%(activeTime)s active).") % {'totalTime': self.timer.total_time_string(),
- 'activeTime': self.timer.active_time_string()
- }
+ if self.timer.active_time < 60:
+ seconds = int(self.timer.active_time)
+ sublabel = ngettext("You completed the puzzle in %d second",
+ "You completed the puzzle in %d seconds", seconds) % seconds
+ elif self.timer.active_time < 3600:
+ minutes = int(self.timer.active_time / 60)
+ seconds = int(self.timer.active_time - minutes*60)
+ minute_string = ngettext("%d minute", "%d minutes", minutes) % minutes
+ second_string = ngettext("%d second", "%d seconds", seconds) % seconds
+ sublabel = _("You completed the puzzle in %(minute)s and %(second)s") % {'minute': minute_string, 'second': second_string}
else:
- sublabel = _("You completed the puzzle in %(totalTime)s.") % {'totalTime': self.timer.total_time_string()}
+ hours = int(self.timer.active_time / 3600)
+ minutes = int((self.timer.active_time - hours*3600) / 60)
+ seconds = int(self.timer.active_time - hours*3600 - minutes*60)
+ hour_string = ngettext("%d hour", "%d hours", hours) % hours
+ minute_string = ngettext("%d minute", "%d minutes", minutes) % minutes
+ second_string = ngettext("%d second", "%d seconds", seconds) % seconds
+ sublabel = _("You completed the puzzle in %(hour)s, %(minute)s and %(second)s") % {'hour': hour_string, 'minute': minute_string, 'second': second_string}
sublabel += "\n"
sublabel += ngettext("You got %(n)s hint.", "You got %(n)s hints.", self.gsd.hints) % {'n':self.gsd.hints}
sublabel += "\n"
diff --git a/gnome-sudoku/src/lib/timer.py b/gnome-sudoku/src/lib/timer.py
index a1079c7..84f6f9a 100644
--- a/gnome-sudoku/src/lib/timer.py
+++ b/gnome-sudoku/src/lib/timer.py
@@ -1,56 +1,6 @@
# -*- coding: utf-8 -*-
-import gtk, gobject
+import gobject
import time
-from gettext import gettext as _
-from gettext import ngettext
-
-def format_time (tim, round_at = None, friendly = False):
- """Format a time for display to the user.
-
- If round_at, we round all times to some number of seconds.
-
- If friendly, we don't bother showing the user more than two
- units. i.e. 3 days 2 hours, or 2 minutes 30 seconds, but not 3
- days, 4 hours, 2 minutes and 3 seconds...
- """
- tim = int(tim)
- time_strings = []
- units = [(int(365.25 * 24 * 60 * 60),
- lambda years: ngettext("%(n)s year", "%(n)s years", years) % {'n': years}),
- (31 * 24 * 60 * 60,
- lambda months: ngettext("%(n)s month", "%(n)s months", months) % {'n': months}),
- (7 * 24 * 60 * 60,
- lambda weeks: ngettext("%(n)s week", "%(n)s weeks", weeks) % {'n': weeks}),
- (24 * 60 * 60,
- lambda days: ngettext("%(n)s day", "%(n)s days", days) % {'n': days}),
- (60 * 60,
- lambda hours: ngettext("%(n)s hour", "%(n)s hours", hours) % {'n': hours}),
- (60,
- lambda minutes: ngettext("%(n)s minute", "%(n)s minutes", minutes) % {'n': minutes}),
- (1,
- lambda seconds: ngettext("%(n)s second", "%(n)s seconds", seconds) % {'n': seconds})]
- for divisor, unit_formatter in units:
- time_covered = tim / divisor
- if time_covered:
- if round_at and len(time_strings) + 1 >= round_at:
- time_covered = int(round(float(tim) / divisor))
- time_strings.append(unit_formatter(time_covered))
- break
- else:
- time_strings.append(unit_formatter(time_covered))
- tim = tim - time_covered * divisor
- if friendly and len(time_strings) > 2:
- time_strings = time_strings[:2]
- if len(time_strings) > 2:
- # Translators... this is a messay way of concatenating
- # lists. In English we do lists this way: 1, 2, 3, 4, 5
- # and 6. This set-up allows for the English system only.
- # You can of course make your language only use commas or
- # ands or spaces or whatever you like by translating both
- # ", " and " and " with the same string.
- return _(" and ").join([_(", ").join(time_strings[0:-1]), time_strings[-1]])
- else:
- return _(" ").join(time_strings)
class ActiveTimer (gobject.GObject):
"""A timer to keep track of how much time a window is active."""
@@ -119,16 +69,11 @@ class ActiveTimer (gobject.GObject):
self.mark_timing()
self.timer_running = False
- def active_time_string (self):
- return format_time(self.active_time)
-
- def total_time_string (self):
- return format_time(self.total_time)
-
if __name__ == '__main__':
+ import gtk
+
def report (timer):
- print 'active:', timer.active_time_string()
- print 'total:', timer.total_time_string()
+ pass
def test_active_timer ():
win = gtk.Window()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]