diff --git a/configure.ac b/configure.ac index 01db86351..77ae4d8c0 100644 --- a/configure.ac +++ b/configure.ac @@ -156,6 +156,17 @@ AC_CHECK_FUNCS(fdwalk) AC_CHECK_FUNCS(mallinfo) AC_CHECK_HEADERS([sys/resource.h]) +# _NL_TIME_FIRST_WEEKDAY is an enum and not a define +AC_MSG_CHECKING([for _NL_TIME_FIRST_WEEKDAY]) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], + [[nl_langinfo(_NL_TIME_FIRST_WEEKDAY);]])], + [langinfo_ok=yes], [langinfo_ok=no]) +AC_MSG_RESULT($langinfo_ok) +if test "$langinfo_ok" = "yes"; then + AC_DEFINE([HAVE__NL_TIME_FIRST_WEEKDAY], [1], + [Define if _NL_TIME_FIRST_WEEKDAY is available]) +fi + # Sets GLIB_GENMARSHAL and GLIB_MKENUMS AM_PATH_GLIB_2_0() G_IR_SCANNER=`$PKG_CONFIG --variable=g_ir_scanner gobject-introspection-1.0` diff --git a/js/ui/calendar.js b/js/ui/calendar.js index 0f8730539..f5448f07b 100644 --- a/js/ui/calendar.js +++ b/js/ui/calendar.js @@ -358,10 +358,7 @@ Calendar.prototype = { this._update(false); })); - // FIXME: This is actually the fallback method for GTK+ for the week start; - // GTK+ by preference uses nl_langinfo (NL_TIME_FIRST_WEEKDAY). We probably - // should add a C function so we can do the full handling. - this._weekStart = NaN; + this._weekStart = Shell.util_get_week_start(); this._weekdate = NaN; this._digitWidth = NaN; this._settings = new Gio.Settings({ schema: 'org.gnome.shell.calendar' }); @@ -369,16 +366,6 @@ Calendar.prototype = { this._settings.connect('changed::' + SHOW_WEEKDATE_KEY, Lang.bind(this, this._onSettingsChange)); this._useWeekdate = this._settings.get_boolean(SHOW_WEEKDATE_KEY); - let weekStartString = Gettext_gtk30.gettext('calendar:week_start:0'); - if (weekStartString.indexOf('calendar:week_start:') == 0) { - this._weekStart = parseInt(weekStartString.substring(20)); - } - - if (isNaN(this._weekStart) || this._weekStart < 0 || this._weekStart > 6) { - log('Translation of "calendar:week_start:0" in GTK+ is not correct'); - this._weekStart = 0; - } - // Find the ordering for month/year in the calendar heading this._headerFormatWithoutYear = '%B'; switch (Gettext_gtk30.gettext('calendar:MY')) { @@ -638,17 +625,7 @@ EventsList.prototype = { this._eventSource.connect('changed', Lang.bind(this, this._update)); this._desktopSettings = new Gio.Settings({ schema: 'org.gnome.desktop.interface' }); this._desktopSettings.connect('changed', Lang.bind(this, this._update)); - let weekStartString = Gettext_gtk30.gettext('calendar:week_start:0'); - if (weekStartString.indexOf('calendar:week_start:') == 0) { - this._weekStart = parseInt(weekStartString.substring(20)); - } - - if (isNaN(this._weekStart) || - this._weekStart < 0 || - this._weekStart > 6) { - log('Translation of "calendar:week_start:0" in GTK+ is not correct'); - this._weekStart = 0; - } + this._weekStart = Shell.util_get_week_start(); this._update(); }, diff --git a/src/shell-util.c b/src/shell-util.c index ef00f44a5..5e53ef240 100644 --- a/src/shell-util.c +++ b/src/shell-util.c @@ -6,6 +6,10 @@ #include #include +#ifdef HAVE__NL_TIME_FIRST_WEEKDAY +#include +#endif + #include #include #include @@ -541,6 +545,62 @@ shell_util_format_date (const char *format, return result; } +/** + * shell_util_get_week_start: + * + * Gets the first week day for the current locale, expressed as a + * number in the range 0..6, representing week days from Sunday to + * Saturday. + * + * Returns: A number representing the first week day for the current + * locale + */ +/* Copied from gtkcalendar.c */ +int +shell_util_get_week_start () +{ + int week_start; +#ifdef HAVE__NL_TIME_FIRST_WEEKDAY + union { unsigned int word; char *string; } langinfo; + int week_1stday = 0; + int first_weekday = 1; + guint week_origin; +#else + char *gtk_week_start; +#endif + +#ifdef HAVE__NL_TIME_FIRST_WEEKDAY + langinfo.string = nl_langinfo (_NL_TIME_FIRST_WEEKDAY); + first_weekday = langinfo.string[0]; + langinfo.string = nl_langinfo (_NL_TIME_WEEK_1STDAY); + week_origin = langinfo.word; + if (week_origin == 19971130) /* Sunday */ + week_1stday = 0; + else if (week_origin == 19971201) /* Monday */ + week_1stday = 1; + else + g_warning ("Unknown value of _NL_TIME_WEEK_1STDAY.\n"); + + week_start = (week_1stday + first_weekday - 1) % 7; +#else + gtk_week_start = dgettext ("gtk30", "calendar:week_start:0"); + + if (strncmp (gtk_week_start, "calendar:week_start:", 20) == 0) + week_start = *(gtk_week_start + 20) - '0'; + else + week_start = -1; + + if (week_start < 0 || week_start > 6) + { + g_warning ("Whoever translated calendar:week_start:0 for GTK+ " + "did so wrongly.\n"); + week_start = 0; + } +#endif + + return week_start; +} + /** * shell_get_event_state: * @event: a #ClutterEvent diff --git a/src/shell-util.h b/src/shell-util.h index 1f431ff62..fcfc6cc4e 100644 --- a/src/shell-util.h +++ b/src/shell-util.h @@ -20,6 +20,7 @@ void shell_util_set_hidden_from_pick (ClutterActor *actor, void shell_util_get_transformed_allocation (ClutterActor *actor, ClutterActorBox *box); +int shell_util_get_week_start (void); char *shell_util_format_date (const char *format, gint64 time_ms);