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



commit 1ac463384271d3bea0ee4f918940748548b2a230
Author: Robert Ancell <robert ancell canonical com>
Date:   Fri Oct 22 17:08:29 2010 +1100

    sudoku: Make puzzle title strings more translatable (Bug #628161)

 gnome-sudoku/src/lib/game_selector.py |   13 +++++++++++--
 gnome-sudoku/src/lib/main.py          |    8 +++++++-
 gnome-sudoku/src/lib/printing.py      |    7 ++++++-
 gnome-sudoku/src/lib/sudoku.py        |   26 --------------------------
 4 files changed, 24 insertions(+), 30 deletions(-)
---
diff --git a/gnome-sudoku/src/lib/game_selector.py b/gnome-sudoku/src/lib/game_selector.py
index 99e551e..f2e7b6a 100644
--- a/gnome-sudoku/src/lib/game_selector.py
+++ b/gnome-sudoku/src/lib/game_selector.py
@@ -118,7 +118,10 @@ class NewOrSavedGameSelector:
             g['game'].split('\n')[0] for g in self.saved_games
             ]
         for cat in sudoku.DifficultyRating.ordered_categories:
-            label = sudoku.DifficultyRating.label_by_cat[cat]
+            label = {'easy': _('Easy'),
+                     'medium': _('Medium'),
+                     'hard': _('Hard'),
+                     'very hard': _('Very hard')}[cat]
             puzzles = self.sudoku_maker.get_puzzles(1, [cat], new = True,
                                                     exclude = saved_games_to_exclude
                                                     )
@@ -183,7 +186,13 @@ class NewOrSavedGameSelector:
             sr = sudoku.SudokuRater(grid.grid)
             sdifficulty = sr.difficulty()
             lastPlayedText = self.format_friendly_date(g['saved_at'])
-            levelText = _("%(level)s puzzle") % {'level': sdifficulty.value_string()}
+            try:
+                levelText = {'easy': _('Easy puzzle'),
+                             'medium': _('Medium puzzle'),
+                             'hard': _('Hard puzzle'),
+                             'very hard': _('Very hard puzzle')}[sdifficulty.value_category()]
+            except KeyError:
+                levelText = sdifficulty.value_category()
             tim = g['timer.active_time']
             if tim >= 3600.0:
                 hours = int(tim / 3600)
diff --git a/gnome-sudoku/src/lib/main.py b/gnome-sudoku/src/lib/main.py
index d0860aa..ffd9429 100644
--- a/gnome-sudoku/src/lib/main.py
+++ b/gnome-sudoku/src/lib/main.py
@@ -662,7 +662,13 @@ class UI (gconf_wrapper.GConfWrapper):
         puzzle = self.gsd.grid.virgin.to_string()
         diff = self.sudoku_maker.get_difficulty(puzzle)
         information = _("Calculated difficulty: ")
-        information += diff.value_string()
+        try:
+            information += {'easy': _('Easy'),
+                            'medium': _('Medium'),
+                            'hard': _('Hard'),
+                            'very hard': _('Very Hard')}[diff.value_category()]
+        except KeyError:
+            information += diff.value_category()
         information += " (%1.2f)" % diff.value
         information += "\n"
         information += _("Number of moves instantly fillable by elimination: ")
diff --git a/gnome-sudoku/src/lib/printing.py b/gnome-sudoku/src/lib/printing.py
index e0f0bf0..9b62dc9 100644
--- a/gnome-sudoku/src/lib/printing.py
+++ b/gnome-sudoku/src/lib/printing.py
@@ -3,6 +3,7 @@ import gtk, cairo, time
 import os.path
 import sudoku, gsudoku, saver, defaults
 from gtk_goodies import gconf_wrapper
+from gettext import gettext as _
 
 def fit_squares_in_rectangle (width, height, n, margin = 0):
     """Optimally fit squares into a rectangle.
@@ -176,8 +177,12 @@ class GamePrinter (gconf_wrapper.GConfWrapper):
             )
         # Convert floating point difficulty into a label string
         sudokus.sort(cmp = lambda a, b: cmp(a[1], b[1]))
+        labels = {'easy': _('Easy'),
+                  'medium': _('Medium'),
+                  'hard': _('Hard'),
+                  'very hard': _('Very hard')}
         sudokus = [(sudoku.sudoku_grid_from_string(puzzle),
-                    "%s (%.2f)" % (sudoku.get_difficulty_category_name(d), d)
+                    "%s (%.2f)" % (labels[sudoku.get_difficulty_category(d)], d)
                     ) for puzzle, d in sudokus]
         sp = SudokuPrinter(sudokus,
                            self.dialog,
diff --git a/gnome-sudoku/src/lib/sudoku.py b/gnome-sudoku/src/lib/sudoku.py
index 72ecfde..0a131f8 100644
--- a/gnome-sudoku/src/lib/sudoku.py
+++ b/gnome-sudoku/src/lib/sudoku.py
@@ -683,12 +683,6 @@ class InteractiveSudoku (SudokuSolver):
 
 
 class DifficultyRating:
-
-    very_hard = _('Very hard')
-    hard = _('Hard')
-    medium = _('Medium')
-    easy = _('Easy')
-
     very_hard_range = (0.75, 10)
     hard_range = (0.6, 0.75)
     medium_range = (0.45, 0.6)
@@ -700,10 +694,6 @@ class DifficultyRating:
                   'easy':easy_range}
 
     ordered_categories = ['easy', 'medium', 'hard', 'very hard']
-    label_by_cat = {'easy':easy,
-                    'medium':medium,
-                    'hard':hard,
-                    'very hard':very_hard}
 
     def __init__ (self,
                   fill_must_fillables,
@@ -768,16 +758,6 @@ class DifficultyRating:
                           ]:
             print name, ': ', stat
 
-    def value_string (self):
-        if self.value > self.very_hard_range[0]:
-            return _(self.very_hard)
-        elif self.value > self.hard_range[0]:
-            return _(self.hard)
-        elif self.value > self.medium_range[0]:
-            return _(self.medium)
-        else:
-            return _(self.easy)
-
     def value_category (self):
         """Get category string, without i18n or capitalization
 
@@ -792,12 +772,6 @@ class DifficultyRating:
         else:
             return 'easy'
 
-def get_difficulty_category_name (diff_float):
-    return DifficultyRating.label_by_cat.get(
-        get_difficulty_category(diff_float),
-        '?'
-        )
-
 def get_difficulty_category (diff_float):
     for category, range in DifficultyRating.categories.items():
         if range[0] <= diff_float < range[1]:



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