[gnome-nibbles/arnaudb/modernize-code: 16/58] Fix a bug.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-nibbles/arnaudb/modernize-code: 16/58] Fix a bug.
- Date: Wed, 10 Jun 2020 17:14:16 +0000 (UTC)
commit 87fbb60d9081ebd9830c118939461f21e34ef95b
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 | 14 ++++++--------
src/nibbles-view.vala | 36 ++++++++++++++++++++----------------
src/preferences-dialog.vala | 2 +-
3 files changed, 27 insertions(+), 25 deletions(-)
---
diff --git a/src/gnome-nibbles.vala b/src/gnome-nibbles.vala
index 50adce4..e7e2d11 100644
--- a/src/gnome-nibbles.vala
+++ b/src/gnome-nibbles.vala
@@ -400,7 +400,7 @@ private 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);
}
@@ -1160,10 +1160,8 @@ private class Scoreboard : 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); // TODO document for translators where this string appears 1/2
+ /* 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);
}
@@ -1260,10 +1258,10 @@ private class ControlsGrid : Grid
internal 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". */
- var player_id = _("Player %d").printf (worm_id + 1); // TODO document for translators where this
string appears 2/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>");
arrow_up.set_from_pixbuf (arrow.rotate_simple (Gdk.PixbufRotation.NONE));
diff --git a/src/nibbles-view.vala b/src/nibbles-view.vala
index e129d6f..82ab867 100644
--- a/src/nibbles-view.vala
+++ b/src/nibbles-view.vala
@@ -146,18 +146,6 @@ private class NibblesView : GtkClutter.Embed
}
}
- /* Colors */
- internal const int NUM_COLORS = 6; // only used in preferences-dialog.vala
- internal static string[] color_lookup =
- {
- N_("red"),
- N_("green"),
- N_("blue"),
- N_("yellow"),
- N_("cyan"),
- N_("purple")
- };
-
internal NibblesView (NibblesGame game)
{
Object (game: game);
@@ -577,7 +565,7 @@ private 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)
@@ -943,11 +931,27 @@ private class NibblesView : GtkClutter.Embed
}
/*\
- * * Utility
+ * * Colors
\*/
- internal 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 9016355..3c91e6f 100644
--- a/src/preferences-dialog.vala
+++ b/src/preferences-dialog.vala
@@ -147,7 +147,7 @@ private class PreferencesDialog : 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]