From a11db8771281e39b8df4acdca40e23f54374642b Mon Sep 17 00:00:00 2001 From: Rafal Luzynski Date: Fri, 31 Mar 2017 00:59:48 +0200 Subject: [PATCH] utils: Use nominative/genitive month names correctly These changes are needed since the standalone (nominative) vs. full date format (genitive) month names support has been introduced in Linux with glibc 2.27. They are also supported in *BSD systems. See also: https://bugzilla.gnome.org/show_bug.cgi?id=749206 https://sourceware.org/bugzilla/show_bug.cgi?id=10871 https://gitlab.gnome.org/GNOME/gnome-calendar/issues/125 --- meson.build | 24 ++++++++++++++++++++++++ src/gcal-date-chooser.c | 21 +++------------------ src/gcal-utils.c | 27 +++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 18 deletions(-) diff --git a/meson.build b/meson.build index 8b8b36a09..a1dc8186d 100644 --- a/meson.build +++ b/meson.build @@ -78,6 +78,30 @@ nl_time_first_weekday_src = ''' config_h.set('HAVE__NL_TIME_FIRST_WEEKDAY', cc.compiles(nl_time_first_weekday_src), description: 'Define if _NL_TIME_FIRST_WEEKDAY is available') +# Not all systems support nl_langinfo (ALTMON_*) +altmon_src = ''' + /* _GNU_SOURCE is required by glibc 2.27. */ + #define _GNU_SOURCE + #include + int main() { + nl_langinfo (ALTMON_1); + nl_langinfo (ALTMON_2); + nl_langinfo (ALTMON_3); + nl_langinfo (ALTMON_4); + nl_langinfo (ALTMON_5); + nl_langinfo (ALTMON_6); + nl_langinfo (ALTMON_7); + nl_langinfo (ALTMON_8); + nl_langinfo (ALTMON_9); + nl_langinfo (ALTMON_10); + nl_langinfo (ALTMON_11); + nl_langinfo (ALTMON_12); + }; +''' + +config_h.set('HAVE_ALTMON', cc.compiles(altmon_src), + description: 'Define if ALTMON_* constants are available') + # Compiler flags common_flags = [ '-DHAVE_CONFIG_H', diff --git a/src/gcal-date-chooser.c b/src/gcal-date-chooser.c index 44268b604..238e16331 100644 --- a/src/gcal-date-chooser.c +++ b/src/gcal-date-chooser.c @@ -224,20 +224,6 @@ calendar_get_weekday_name (gint i) return text; } -/* 0 = january */ -static gchar * -calendar_get_month_name (gint i) -{ - GDateTime *date; - gchar *text; - - date = g_date_time_new_local (2015, i + 1, 1, 1, 1, 1); - text = g_date_time_format (date, "%B"); - g_date_time_unref (date); - - return text; -} - static void calendar_init_weekday_display (GcalDateChooser *self) { @@ -257,7 +243,7 @@ format_month (GcalMultiChoice *choice, gint value, gpointer data) { - return calendar_get_month_name (value); + return g_strdup (gcal_get_month_name (value)); } static void @@ -269,9 +255,8 @@ calendar_init_month_display (GcalDateChooser *self) for (i = 0; i < 12; i++) { - month = calendar_get_month_name (i); - months[i] = g_strdup_printf ("%s", month); - g_free (month); + month = gcal_get_month_name (i); + months[i] = g_strdup (month); } months[12] = NULL; diff --git a/src/gcal-utils.c b/src/gcal-utils.c index 9846a59bf..c76465653 100644 --- a/src/gcal-utils.c +++ b/src/gcal-utils.c @@ -20,6 +20,9 @@ #define G_LOG_DOMAIN "Utils" +/* langinfo.h in glibc 2.27 defines ALTMON_* only if _GNU_SOURCE is defined. */ +#define _GNU_SOURCE + #include "gcal-enums.h" #include "gcal-utils.h" #include "gcal-event-widget.h" @@ -57,6 +60,29 @@ ab_day[7] = static const gint month_item[12] = { + /* ALTMON_* constants have been introduced in glibc 2.27 (Feb 1, 2018), also + * have been supported in *BSD family (but not in OS X) since 1990s. + * If they exist they are the correct way to obtain the month names in + * nominative case, standalone, without the day number, as used in the + * calendar header. This is obligatory in some languages (Slavic, Baltic, + * Greek, etc.) but also recommended to use in all languages because for + * other languages there is no difference between ALTMON_* and MON_*. + * If ALTMON_* is not supported then we must use MON_*. + */ +#ifdef HAVE_ALTMON + ALTMON_1, + ALTMON_2, + ALTMON_3, + ALTMON_4, + ALTMON_5, + ALTMON_6, + ALTMON_7, + ALTMON_8, + ALTMON_9, + ALTMON_10, + ALTMON_11, + ALTMON_12 +#else MON_1, MON_2, MON_3, @@ -69,6 +95,7 @@ month_item[12] = MON_10, MON_11, MON_12 +#endif }; #define SCROLL_HARDNESS 10.0 -- GitLab