calendar: Improve week start handling
Add a helper function (mostly copied from gtkcalendar.c) for getting the first week day for the current locale, using nl_langinfo if available and falling back to the GTK+ gettext fallback otherwise. Use that function in the calendar, so that the LC_TIME setting is used if possible. https://bugzilla.gnome.org/show_bug.cgi?id=649078
This commit is contained in:
@ -6,6 +6,10 @@
|
||||
#include <glib/gi18n-lib.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#ifdef HAVE__NL_TIME_FIRST_WEEKDAY
|
||||
#include <langinfo.h>
|
||||
#endif
|
||||
|
||||
#include <libxml/parser.h>
|
||||
#include <libxml/tree.h>
|
||||
#include <libxml/xmlmemory.h>
|
||||
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user