[gnome-games] sudoku: Make last played strings more translatable (Bug #628161)



commit 9e61d435cebdacc5017ac21008d712f5d3233e45
Author: Robert Ancell <robert ancell canonical com>
Date:   Fri Oct 22 16:03:42 2010 +1100

    sudoku: Make last played strings more translatable (Bug #628161)

 gnome-sudoku/src/lib/game_selector.py |   35 ++++++++++++++++++++++++++++++--
 gnome-sudoku/src/lib/timer.py         |   27 -------------------------
 2 files changed, 32 insertions(+), 30 deletions(-)
---
diff --git a/gnome-sudoku/src/lib/game_selector.py b/gnome-sudoku/src/lib/game_selector.py
index 82120a1..30ff747 100644
--- a/gnome-sudoku/src/lib/game_selector.py
+++ b/gnome-sudoku/src/lib/game_selector.py
@@ -4,7 +4,9 @@ import os.path
 import sudoku, saver, sudoku_maker
 import sudoku_thumber
 from gettext import gettext as _
-from timer import format_time, format_friendly_date
+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
@@ -145,6 +147,33 @@ class NewOrSavedGameSelector:
                                         puzzle
                                         ))
 
+    def format_friendly_date (self, tim):
+        local_tim = time.localtime(tim)
+        diff = int(time.time() - tim)
+        curr_hour, curr_min = time.localtime()[3:5]
+        now_to_yesterday = curr_hour * 60 * 60 + curr_min * 60
+        if diff < now_to_yesterday:
+            # Then we're today
+            if diff < 60: # within the minute
+                return ngettext("Last played %(n)s second ago",
+                                "Last played %(n)s seconds ago", diff) % {'n': diff}
+            elif diff < (60 * 60): # within the hour...
+                minute = int(diff / 60)
+                return ngettext("Last played %(n)s minute ago",
+                                "Last played %(n)s minutes ago", minute) % {'n': minute}
+            else:
+                # Translators, see strftime manual in order to translate %? format strings
+                return time.strftime(_("Last played at %I:%M %p"), local_tim)
+        elif diff < now_to_yesterday + (60 * 60 * 24):
+            # Translators, see strftime manual in order to translate %? format strings
+            return time.strftime(_("Last played yesterday at %I:%M %p"), local_tim)
+        elif diff < now_to_yesterday + (60 * 60 * 24) * 6:
+            # Translators, see strftime manual in order to translate %? format strings
+            return time.strftime(_("Last played on %A at %I:%M %p"), local_tim)
+        else:
+            # Translators, see strftime manual in order to translate %? format strings
+            return time.strftime(_("Last played on %B %e %Y"), local_tim)
+
     @simple_debug
     def make_saved_game_model (self):
         # Description, Image, Last-Access time (for sorting), Puzzle (jar)
@@ -154,8 +183,8 @@ class NewOrSavedGameSelector:
             grid = sudoku.sudoku_grid_from_string(game)
             sr = sudoku.SudokuRater(grid.grid)
             sdifficulty = sr.difficulty()
-            lastPlayedText = _("Last played %(timeAgo)s") % {'timeAgo': format_friendly_date(g['saved_at'])}
-            levelText =  _("%(level)s puzzle") % {'level': sdifficulty.value_string()}
+            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)}
             desc = "<b><i>%s</i></b>\n<span size='small'><i>%s</i>\n<i>%s.</i></span>" % (
diff --git a/gnome-sudoku/src/lib/timer.py b/gnome-sudoku/src/lib/timer.py
index c37511a..a1079c7 100644
--- a/gnome-sudoku/src/lib/timer.py
+++ b/gnome-sudoku/src/lib/timer.py
@@ -52,33 +52,6 @@ def format_time (tim, round_at = None, friendly = False):
     else:
         return _(" ").join(time_strings)
 
-def format_friendly_date (tim):
-    local_tim = time.localtime(tim)
-    diff = int(time.time() - tim)
-    curr_hour, curr_min = time.localtime()[3:5]
-    now_to_yesterday = curr_hour * 60 * 60 + curr_min * 60
-    if diff < now_to_yesterday:
-        # Then we're today
-        if diff < 60: # within the minute
-            return ngettext("%(n)s second ago",
-                            "%(n)s seconds ago", diff) % {'n': diff}
-        elif diff < (60 * 60): # within the hour...
-            minute = int(diff / 60)
-            return ngettext("%(n)s minute ago",
-                            "%(n)s minutes ago", minute) % {'n': minute}
-        else:
-            # Translators, see strftime manual in order to translate %? format strings
-            return time.strftime(_("at %I:%M %p"), local_tim)
-    elif diff < now_to_yesterday + (60 * 60 * 24):
-        # Translators, see strftime manual in order to translate %? format strings
-        return time.strftime(_("yesterday at %I:%M %p"), local_tim)
-    elif diff < now_to_yesterday + (60 * 60 * 24) * 6:
-        # Translators, see strftime manual in order to translate %? format strings
-        return time.strftime(_("%A %I:%M %p"), local_tim)
-    else:
-        # Translators, see strftime manual in order to translate %? format strings
-        return time.strftime(_("%B %e"), local_tim)
-
 class ActiveTimer (gobject.GObject):
     """A timer to keep track of how much time a window is active."""
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]