diff --git a/meson.build b/meson.build index 8b8b36a096671136c8dff0840a91fe9c49a5f9af..a1dc8186d8b0c82a42fe718639f35c971b5f5d1f 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 44268b6049fb6dd2c3e47f1f6a03857b05605cd0..238e16331a7a24dad19e1fb5788fa29af837fd2d 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 9846a59bf2d76b0a7946f3b3719dafcd58429849..c7646565387412ceaabc3b04132403c37e73396d 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