[hitori/13-localised-board: 2/2] interface: Support localised cell text
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [hitori/13-localised-board: 2/2] interface: Support localised cell text
- Date: Tue, 5 Mar 2019 13:37:35 +0000 (UTC)
commit 3004fb9a1e7ce8f9b92126a2f0dc29d1f3ca043d
Author: Philip Withnall <withnall endlessm com>
Date: Tue Mar 5 13:36:09 2019 +0000
interface: Support localised cell text
This should allow translators to choose whether to display the game
board in their local numerals, or in the default Arabic numerals.
Signed-off-by: Philip Withnall <withnall endlessm com>
Fixes: #13
src/interface.c | 35 ++++++++++++++++++++++++++++++++---
1 file changed, 32 insertions(+), 3 deletions(-)
---
diff --git a/src/interface.c b/src/interface.c
index 1e15d4a..492018b 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -131,11 +131,41 @@ lookup_color (GtkStyleContext *style_context, const gchar *name, GdkRGBA *result
}
}
+/* Generate the text for a given cell, potentially localised to the current locale. */
+static const gchar *
+localise_cell_digit (Hitori *hitori,
+ const HitoriVector *pos)
+{
+ guchar value = hitori->board[pos->x][pos->y].num;
+
+ G_STATIC_ASSERT (MAX_BOARD_SIZE < 11);
+
+ switch (value) {
+ /* Translators: This is a digit rendered in a cell on the game board.
+ * Translate it to your locale’s number system if you wish the game
+ * board to be rendered in those digits. Otherwise, leave the digits as
+ * Arabic numerals. */
+ case 1: return C_("Board cell", "1");
+ case 2: return C_("Board cell", "2");
+ case 3: return C_("Board cell", "3");
+ case 4: return C_("Board cell", "4");
+ case 5: return C_("Board cell", "5");
+ case 6: return C_("Board cell", "6");
+ case 7: return C_("Board cell", "7");
+ case 8: return C_("Board cell", "8");
+ case 9: return C_("Board cell", "9");
+ case 10: return C_("Board cell", "10");
+ case 11: return C_("Board cell", "11");
+ default:
+ g_assert_not_reached ();
+ }
+}
+
static void
draw_cell (Hitori *hitori, GtkStyleContext *style_context, cairo_t *cr, gdouble cell_size, gdouble x_pos,
gdouble y_pos,
HitoriVector iter)
{
- gchar *text;
+ const gchar *text;
PangoLayout *layout;
gint text_width, text_height;
GtkStateFlags state;
@@ -214,7 +244,7 @@ draw_cell (Hitori *hitori, GtkStyleContext *style_context, cairo_t *cr, gdouble
cairo_stroke (cr);
/* Draw the text */
- text = g_strdup_printf ("%u", hitori->board[iter.x][iter.y].num);
+ text = localise_cell_digit (hitori, &iter);
layout = pango_cairo_create_layout (cr);
pango_layout_set_text (layout, text, -1);
@@ -245,7 +275,6 @@ draw_cell (Hitori *hitori, GtkStyleContext *style_context, cairo_t *cr, gdouble
pango_cairo_show_layout (cr, layout);
- g_free (text);
g_object_unref (layout);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]