[gnome-nibbles/arnaudb/fix-bugs-3-34: 1/3] Fix a bug.



commit 3920aa115ca4d49ac02ef0b37c5cb49c0e48166e
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed May 27 01:03:16 2020 +0200

    Fix a bug.
    
    The colorval_name() return values
    were used both in the Preferences
    dialog, where they needed to have
    a translation, and in a technical
    context, where an English word is
    required for parsing it as color.

 src/gnome-nibbles.vala      | 12 +++++-------
 src/nibbles-view.vala       | 36 ++++++++++++++++++++----------------
 src/preferences-dialog.vala |  2 +-
 3 files changed, 26 insertions(+), 24 deletions(-)
---
diff --git a/src/gnome-nibbles.vala b/src/gnome-nibbles.vala
index 18302c1..8d253ab 100644
--- a/src/gnome-nibbles.vala
+++ b/src/gnome-nibbles.vala
@@ -371,7 +371,7 @@ public class Nibbles : Gtk.Application
         foreach (var worm in game.worms)
         {
             var color = game.worm_props.get (worm).color;
-            scoreboard.register (worm, NibblesView.colorval_name (color), scoreboard_life);
+            scoreboard.register (worm, NibblesView.colorval_name_untranslated (color), scoreboard_life);
             worm.notify["lives"].connect (scoreboard.update);
             worm.notify["score"].connect (scoreboard.update);
         }
@@ -1092,10 +1092,8 @@ private class Scoreboard : Gtk.Box
         var color = Pango.Color ();
         color.parse (color_name);
 
-        /* FIXME: Consider changing this to "Worm %d"
-         * It's set to "Player %d" for now to avoid a string change for 3.20.
-         */
-        var box = new PlayerScoreBox (_("Player %d").printf (worm.id + 1), color, worm.score, worm.lives, 
life_pixbuf);
+        /* Translators: text displayed under the game view, presenting the number of remaining lives; the %d 
is replaced by the number that identifies the player */
+        var box = new PlayerScoreBox (_("Player %d").printf (worm.id + 1), color, worm.score, worm.lives, 
life_pixbuf); // FIXME: Consider changing this to "Worm %d"; It's set to "Player %d" for now to avoid a 
string change for 3.20.
         boxes.set (box, worm);
         add (box);
     }
@@ -1210,9 +1208,9 @@ private class ControlsGrid : Gtk.Grid
     public ControlsGrid (int worm_id, WormProperties worm_props, Gdk.Pixbuf arrow, Gdk.Pixbuf arrow_key)
     {
         var color = Pango.Color ();
-        color.parse (NibblesView.colorval_name (worm_props.color));
+        color.parse (NibblesView.colorval_name_untranslated (worm_props.color));
 
-        /* Translators: the player's number, e.g. "Player 1" or "Player 2". */
+        /* Translators: text displayed in a screen showing the keys used by the players; the %d is replaced 
by the number that identifies the player */
         var player_id = _("Player %d").printf (worm_id + 1);
         name_label.set_markup (@"<b><span font-family=\"Sans\" color=\"$(color.to_string 
())\">$(player_id)</span></b>");
 
diff --git a/src/nibbles-view.vala b/src/nibbles-view.vala
index d76617e..694e999 100644
--- a/src/nibbles-view.vala
+++ b/src/nibbles-view.vala
@@ -146,18 +146,6 @@ public class NibblesView : GtkClutter.Embed
         }
     }
 
-    /* Colors */
-    public const int NUM_COLORS = 6;
-    public static string[] color_lookup =
-    {
-      N_("red"),
-      N_("green"),
-      N_("blue"),
-      N_("yellow"),
-      N_("cyan"),
-      N_("purple")
-    };
-
     public NibblesView (NibblesGame game)
     {
         this.game = game;
@@ -580,7 +568,7 @@ public class NibblesView : GtkClutter.Embed
             var player_id = _("Player %d").printf (worm.id + 1);
             var label = new Clutter.Text.with_text ("Monospace 10", @"<b>$(player_id)</b>");
             label.set_use_markup (true);
-            label.set_color (Clutter.Color.from_string (colorval_name (color)));
+            label.set_color (Clutter.Color.from_string (colorval_name_untranslated (color)));
 
             var middle = worm.length / 2;
             if (worm.direction == WormDirection.UP || worm.direction == WormDirection.DOWN)
@@ -946,11 +934,27 @@ public class NibblesView : GtkClutter.Embed
     }
 
     /*\
-    * * Utility
+    * * Colors
     \*/
 
-    public static string colorval_name (int colorval)
+    internal const int NUM_COLORS = 6;      // only used in preferences-dialog.vala
+    private static string[,] color_lookup =
+    {
+        { "red",    N_("red")    },
+        { "green",  N_("green")  },
+        { "blue",   N_("blue")   },
+        { "yellow", N_("yellow") },
+        { "cyan",   N_("cyan")   },
+        { "purple", N_("purple") }
+    };
+
+    internal static string colorval_name_untranslated (int colorval)
+    {
+        return color_lookup[colorval, 0];
+    }
+
+    internal static string colorval_name_translated (int colorval)
     {
-        return _(color_lookup[colorval]);
+        return _(color_lookup[colorval, 1]);
     }
 }
diff --git a/src/preferences-dialog.vala b/src/preferences-dialog.vala
index f054a10..4120ce2 100644
--- a/src/preferences-dialog.vala
+++ b/src/preferences-dialog.vala
@@ -158,7 +158,7 @@ private class PreferencesDialog : Gtk.Dialog
         foreach (var combo_box in combo_boxes)
         {
             for (int i = 0; i < NibblesView.NUM_COLORS; i++)
-                combo_box.append_text (NibblesView.colorval_name (i));
+                combo_box.append_text (NibblesView.colorval_name_translated (i));
 
             var id = combo_boxes.index_of (combo_box);
 


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