gnome-games r8068 - in trunk/glchess/src/lib: chess gtkui scene/cairo scene/opengl



Author: rancell
Date: Sat Oct 18 05:14:35 2008
New Revision: 8068
URL: http://svn.gnome.org/viewvc/gnome-games?rev=8068&view=rev

Log:
Added context to rank and file strings and piece name strings (Bug #475147)
Translate board co-ordinates in human readable form (still SAN and LAN todo)



Modified:
   trunk/glchess/src/lib/chess/__init__.py
   trunk/glchess/src/lib/gtkui/chessview.py
   trunk/glchess/src/lib/gtkui/dialogs.py
   trunk/glchess/src/lib/scene/cairo/__init__.py
   trunk/glchess/src/lib/scene/opengl/opengl.py

Modified: trunk/glchess/src/lib/chess/__init__.py
==============================================================================
--- trunk/glchess/src/lib/chess/__init__.py	(original)
+++ trunk/glchess/src/lib/chess/__init__.py	Sat Oct 18 05:14:35 2008
@@ -3,3 +3,84 @@
 import lan
 import san
 import fics
+
+import gettext
+_ = gettext.gettext
+
+                 # Translators: The first file on the chess board. Do not translate the 'chess-file|' text
+_fileStrings = {'a': _('chess-file|a'),
+                 # Translators: The second file on the chess board. Do not translate the 'chess-file|' text
+                'b': _('chess-file|b'),
+                 # Translators: The third file on the chess board. Do not translate the 'chess-file|' text                
+                'c': _('chess-file|c'),
+                 # Translators: The fourth file on the chess board. Do not translate the 'chess-file|' text                
+                'd': _('chess-file|d'),
+                 # Translators: The fifth file on the chess board. Do not translate the 'chess-file|' text                
+                'e': _('chess-file|e'),
+                 # Translators: The sixth file on the chess board. Do not translate the 'chess-file|' text                
+                'f': _('chess-file|f'),
+                 # Translators: The seventh file on the chess board. Do not translate the 'chess-file|' text                
+                'g': _('chess-file|g'),
+                 # Translators: The eigth file on the chess board. Do not translate the 'chess-file|' text                
+                'h': _('chess-file|h')}
+_fileMap = {}
+for (key, f) in _fileStrings.iteritems():
+    try:
+        _fileMap[key] = f.split('|', 1)[1]
+    except IndexError:
+        _fileMap[key] = f
+
+                 # Translators: The first rank on the chess board. Do not translate the 'chess-rank|' text
+_rankStrings = {'1': _('chess-rank|1'),
+                 # Translators: The second rank on the chess board. Do not translate the 'chess-rank|' text                
+                '2': _('chess-rank|2'),
+                 # Translators: The third rank on the chess board. Do not translate the 'chess-rank|' text
+                '3': _('chess-rank|3'),
+                 # Translators: The fourth rank on the chess board. Do not translate the 'chess-rank|' text
+                '4': _('chess-rank|4'),
+                 # Translators: The fifth rank on the chess board. Do not translate the 'chess-rank|' text                
+                '5': _('chess-rank|5'),
+                 # Translators: The sixth rank on the chess board. Do not translate the 'chess-rank|' text                
+                '6': _('chess-rank|6'),
+                 # Translators: The seventh rank on the chess board. Do not translate the 'chess-rank|' text                
+                '7': _('chess-rank|7'),
+                 # Translators: The eigth rank on the chess board. Do not translate the 'chess-rank|' text                
+                '8': _('chess-rank|8')}
+                
+_rankMap = {}
+for (key, r) in _rankStrings.iteritems():
+    try:
+        _rankMap[key] = r.split('|', 1)[1]
+    except IndexError:
+        _rankMap[key] = r
+
+def translate_file(file):
+    """Get the translated form of a file.
+    
+    'file' is the file to translate ('a'-'h')
+    
+    Returns a string representing this file.
+    """
+    return _fileMap[file]
+
+def translate_rank(rank):
+    """Get the translated form of a rank.
+    
+    'rank' is the rank to translate ('1'-'8')
+    
+    Returns a string representing this rank.
+    """
+    return _rankMap[rank]
+
+positionStrings = {'a1': 'chess-position|a1'}
+
+def translate_coordinate(coordinate):
+    """Get the translated form of a chess board coordinate.
+    
+    'coordinate' is the coordinate to translate ('a1'-'h8')
+    
+    Returns a string representing this position.
+    """
+    # FIXME: Assumes files are always before ranks. Should probably make all
+    # 64 coordinates translatable to be strictly translatable
+    return _fileMap[coordinate[0]] + _rankMap[coordinate[1]]

Modified: trunk/glchess/src/lib/gtkui/chessview.py
==============================================================================
--- trunk/glchess/src/lib/gtkui/chessview.py	(original)
+++ trunk/glchess/src/lib/gtkui/chessview.py	Sat Oct 18 05:14:35 2008
@@ -502,7 +502,10 @@
                 victimType = move.victim.getType()
             else:
                 victimType = None
-            description = descriptions[colour, pieceType, victimType] % {'start': move.start, 'end': move.end}
+            start = glchess.chess.translate_coordinate(move.start)
+            end = glchess.chess.translate_coordinate(move.end)            
+
+            description = descriptions[colour, pieceType, victimType] % {'start': start, 'end': end}
 
         CHECK     = 'CHECK'
         CHECKMATE = 'CHECKMATE'

Modified: trunk/glchess/src/lib/gtkui/dialogs.py
==============================================================================
--- trunk/glchess/src/lib/gtkui/dialogs.py	(original)
+++ trunk/glchess/src/lib/gtkui/dialogs.py	Sat Oct 18 05:14:35 2008
@@ -610,15 +610,19 @@
         promotionModel = gtk.ListStore(str, str)
         widget = self.__gui.get_widget('promotion_type_combo')
         widget.set_model(promotionModel)
-                          # Translators: Promotion Combo: Promote to a queen
-        promotion_list = [('queen',  _('Queen')),
-                          # Translators: Promotion Combo: Promote to a knight
-                          ('knight', _('Knight')),
-                          # Translators: Promotion Combo: Promote to a rook
-                          ('rook',   _('Rook')),
-                          # Translators: Promotion Combo: Promote to a bishop
-                          ('bishop', _('Bishop'))]
+                          # Translators: Promotion Combo: Promote to a queen. Do not translate the 'chess-piece|' text.
+        promotion_list = [('queen',  _('chess-piece|Queen')),
+                          # Translators: Promotion Combo: Promote to a knight. Do not translate the 'chess-piece|' text.
+                          ('knight', _('chess-piece|Knight')),
+                          # Translators: Promotion Combo: Promote to a rook. Do not translate the 'chess-piece|' text.
+                          ('rook',   _('chess-piece|Rook')),
+                          # Translators: Promotion Combo: Promote to a bishop. Do not translate the 'chess-piece|' text.
+                          ('bishop', _('chess-piece|Bishop'))]
         for (key, label) in promotion_list:
+            try:
+                label = label.split('|', 1)[1]
+            except IndexError:
+                pass
             iter = promotionModel.append()
             promotionModel.set(iter, 0, label, 1, key)
             

Modified: trunk/glchess/src/lib/scene/cairo/__init__.py
==============================================================================
--- trunk/glchess/src/lib/scene/cairo/__init__.py	(original)
+++ trunk/glchess/src/lib/scene/cairo/__init__.py	Sat Oct 18 05:14:35 2008
@@ -364,14 +364,10 @@
 
         # Draw numbering
         if self.showNumbering:
-            offset = 0
             context.set_source_rgb(*NUMBERING_COLOUR)
             context.set_font_size(self.squareSize * 0.4)
             context.select_font_face("sans-serif", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD)
-            # Chess board columns (files) label marked for translation. Please translate to the first eight letters of your alphabet, or the most appropriate eight characters/symbols for labelling the columns of a chess board. 
-            files = [_('a'), _('b'), _('c'), _('d'), _('e'), _('f'), _('g'), _('h')]
-            # Chess board rows (ranks) label marked for translation. Please translate to the first eight numbers with your native number symbols, or the most appropriate eight numbers/symbols for labelling the rows of a chess board.
-            ranks = [_('8'), _('7'), _('6'), _('5'), _('4'), _('3'), _('2'), _('1')]
+            
             def drawCenteredText(x, y, text):
                 (_, _, w, h, _, _) = context.text_extents('b')
                 matrix = context.get_matrix()
@@ -380,11 +376,14 @@
                 context.move_to(-w/2, h/2)
                 context.show_text(text)
                 context.set_matrix(matrix)
+            offset = 0
             for i in xrange(8):
-                drawCenteredText(offset - self.squareSize * 3.5, -self.squareSize * 4.25, files[i])
-                drawCenteredText(offset - self.squareSize * 3.5, self.squareSize * 4.25, files[i])
-                drawCenteredText(-self.squareSize * 4.25, offset - self.squareSize * 3.5, ranks[i])
-                drawCenteredText(self.squareSize * 4.25, offset - self.squareSize * 3.5, ranks[i])
+                f = 'abcdefgh'[i]
+                r = '87654321'[i]
+                drawCenteredText(offset - self.squareSize * 3.5, -self.squareSize * 4.25, glchess.chess.translate_file(f))
+                drawCenteredText(offset - self.squareSize * 3.5, self.squareSize * 4.25, glchess.chess.translate_file(f))
+                drawCenteredText(-self.squareSize * 4.25, offset - self.squareSize * 3.5, glchess.chess.translate_rank(r))
+                drawCenteredText(self.squareSize * 4.25, offset - self.squareSize * 3.5, glchess.chess.translate_rank(r))
                 offset += self.squareSize
         
         # Draw squares

Modified: trunk/glchess/src/lib/scene/opengl/opengl.py
==============================================================================
--- trunk/glchess/src/lib/scene/opengl/opengl.py	(original)
+++ trunk/glchess/src/lib/scene/opengl/opengl.py	Sat Oct 18 05:14:35 2008
@@ -583,11 +583,6 @@
         TEXTURE_WIDTH = WIDTH*16
         TEXTURE_HEIGHT = HEIGHT
 
-        # Chess board columns (files) label marked for translation. Please translate to the first eight letters of your alphabet, or the most appropriate eight characters/symbols for labelling the columns of a chess board. 
-        files = [_('a'), _('b'), _('c'), _('d'), _('e'), _('f'), _('g'), _('h')]
-        # Chess board rows (ranks) label marked for translation. Please translate to the first eight numbers with your native number symbols, or the most appropriate eight numbers/symbols for labelling the rows of a chess board.
-        ranks = [_('1'), _('2'), _('3'), _('4'), _('5'), _('6'), _('7'), _('8')]
-
         surface = cairo.ImageSurface(cairo.FORMAT_A8, TEXTURE_WIDTH, TEXTURE_HEIGHT)
         context = cairo.Context(surface)
         context.set_source_rgba(1.0, 1.0, 1.0, 1.0)
@@ -605,13 +600,14 @@
             context.show_text(text)
             context.set_matrix(matrix)
 
-        xoffset = WIDTH * 0.5
         yoffset = HEIGHT * 0.5
+        xoffset = WIDTH * 0.5
         for i in xrange(8):
-            drawCenteredText(xoffset, yoffset, scale, files[i])
-            drawCenteredText(xoffset + (WIDTH * 8), yoffset, scale, ranks[i])
+            f = 'abcdefgh'[i]
+            r = '12345678'[i]
+            drawCenteredText(xoffset, yoffset, scale, glchess.chess.translate_file(f))
+            drawCenteredText(xoffset + (WIDTH * 8), yoffset, scale, glchess.chess.translate_rank(r))
             xoffset += WIDTH
-        data = surface.get_data()
 
         t = glGenTextures(1)
         glBindTexture(GL_TEXTURE_2D, t)
@@ -620,7 +616,8 @@
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
-        
+
+        data = surface.get_data()        
         try:
             gluBuild2DMipmaps(GL_TEXTURE_2D, GL_ALPHA, TEXTURE_WIDTH, TEXTURE_HEIGHT,
                               GL_ALPHA, GL_UNSIGNED_BYTE, str(data))



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