From 605073b0b9a6050aa720a2835a60383278b95347 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 12 Jun 2005 06:59:43 +0000 Subject: [PATCH] Allow localization of the format in which the year is displayed. (#135451, 2005-06-12 Matthias Clasen * gtk/gtkcalendar.c (calendar_paint_header): (gtk_calendar_size_request): Allow localization of the format in which the year is displayed. (#135451, Paisa Seeluangsawat) --- ChangeLog | 5 +++++ ChangeLog.pre-2-10 | 5 +++++ ChangeLog.pre-2-8 | 5 +++++ gtk/gtkcalendar.c | 49 ++++++++++++++++++++++++++++++++++------------ 4 files changed, 52 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4dee567d38..cc8f11e2fd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2005-06-12 Matthias Clasen + * gtk/gtkcalendar.c (calendar_paint_header): + (gtk_calendar_size_request): Allow localization of the + format in which the year is displayed. (#135451, Paisa + Seeluangsawat) + * gdk/*.h: Cleanup. (#169648, Fabricio Barros Cabral) * gdk/gdkcairo.c: Small doc additions. diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 4dee567d38..cc8f11e2fd 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,5 +1,10 @@ 2005-06-12 Matthias Clasen + * gtk/gtkcalendar.c (calendar_paint_header): + (gtk_calendar_size_request): Allow localization of the + format in which the year is displayed. (#135451, Paisa + Seeluangsawat) + * gdk/*.h: Cleanup. (#169648, Fabricio Barros Cabral) * gdk/gdkcairo.c: Small doc additions. diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 4dee567d38..cc8f11e2fd 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,5 +1,10 @@ 2005-06-12 Matthias Clasen + * gtk/gtkcalendar.c (calendar_paint_header): + (gtk_calendar_size_request): Allow localization of the + format in which the year is displayed. (#135451, Paisa + Seeluangsawat) + * gdk/*.h: Cleanup. (#169648, Fabricio Barros Cabral) * gdk/gdkcairo.c: Small doc additions. diff --git a/gtk/gtkcalendar.c b/gtk/gtkcalendar.c index 1183c34e44..8fe48ec2e7 100644 --- a/gtk/gtkcalendar.c +++ b/gtk/gtkcalendar.c @@ -1535,16 +1535,21 @@ gtk_calendar_size_request (GtkWidget *widget, logical_rect.width + 8); max_header_height = MAX (max_header_height, logical_rect.height); } + priv->max_year_width = 0; - for (i=0; i<10; i++) - { - g_snprintf (buffer, sizeof (buffer), "%d%d%d%d", i,i,i,i); - pango_layout_set_text (layout, buffer, -1); - pango_layout_get_pixel_extents (layout, NULL, &logical_rect); - priv->max_year_width = MAX (priv->max_year_width, - logical_rect.width + 8); - max_header_height = MAX (max_header_height, logical_rect.height); - } + /* Translators: This is a text measurement template. + * Translate it to the widest year text. + * + * Don't include the prefix "year measurement template|" + * in the translation. + * + * If you don't understand this, leave it as "2000" + */ + pango_layout_set_text (layout, Q_("year measurement template|2000"), -1); + pango_layout_get_pixel_extents (layout, NULL, &logical_rect); + priv->max_year_width = MAX (priv->max_year_width, + logical_rect.width + 8); + max_header_height = MAX (max_header_height, logical_rect.height); } else { @@ -1780,6 +1785,9 @@ calendar_paint_header (GtkCalendar *calendar) PangoLayout *layout; PangoRectangle logical_rect; gboolean year_left; + time_t tmp_time; + struct tm *tm; + gchar *str; if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) year_left = priv->year_before; @@ -1798,10 +1806,27 @@ calendar_paint_header (GtkCalendar *calendar) GTK_STATE_NORMAL, GTK_SHADOW_OUT, NULL, widget, "calendar", 0, 0, header_width, priv->header_h); + + tmp_time = 1; /* Jan 1 1970, 00:00:01 UTC */ + tm = gmtime (&tmp_time); + tm->tm_year = calendar->year - 1900; + + /* Translators: This dictates how the year is displayed in + * gtkcalendar widget. See strftime() manual for the format. + * Use only ASCII in the translation. + * + * Also look for the msgid "year measurement template|2000". + * Translate that entry to a year with the widest output of this + * msgid. + * + * Don't include the prefix "calendar year format|" in the + * translation. "%Y" is appropriate for most locales. + */ + strftime (buffer, sizeof (buffer), Q_("calendar year format|%Y"), tm); + str = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL); + layout = gtk_widget_create_pango_layout (widget, str); + g_free (str); - - g_snprintf (buffer, sizeof (buffer), "%d", calendar->year); - layout = gtk_widget_create_pango_layout (widget, buffer); pango_layout_get_pixel_extents (layout, NULL, &logical_rect); /* Draw title */