Use the Win32 thread locale's first day of week setting on Win32.

2006-10-07  Tor Lillqvist  <tml@novell.com>

	* gtk/gtkcalendar.c (gtk_calendar_init): Use the Win32 thread
	locale's first day of week setting on Win32. (#339752, Bogdan
	Nicula) Don't do this if one of the environment variables that
	affect gettext is set, though. In that case use the week start day
	from the corresponding message catalog.

	Unfortunately the same logic isn't possible in the weekday and
	month name lookup; there even if you have set one of the
	aforementioned environment variables, you still get the weekday
	and month names from the Win32 thread locale. Yes, this is
	inconsistent.

	Use only wide-character API in the Win32 code in this file, too.
This commit is contained in:
Tor Lillqvist 2006-10-07 21:32:53 +00:00 committed by Tor Lillqvist
parent c52d217e07
commit e4581869b4
2 changed files with 54 additions and 33 deletions

View File

@ -1,3 +1,19 @@
2006-10-07 Tor Lillqvist <tml@novell.com>
* gtk/gtkcalendar.c (gtk_calendar_init): Use the Win32 thread
locale's first day of week setting on Win32. (#339752, Bogdan
Nicula) Don't do this if one of the environment variables that
affect gettext is set, though. In that case use the week start day
from the corresponding message catalog.
Unfortunately the same logic isn't possible in the weekday and
month name lookup; there even if you have set one of the
aforementioned environment variables, you still get the weekday
and month names from the Win32 thread locale. Yes, this is
inconsistent.
Use only wide-character API in the Win32 code in this file, too.
2006-10-06 Matthias Clasen <mclasen@redhat.com> 2006-10-06 Matthias Clasen <mclasen@redhat.com>
* gtk/gtkfilechooser.c (gtk_file_chooser_set_select_multiple): * gtk/gtkfilechooser.c (gtk_file_chooser_set_select_multiple):

View File

@ -560,10 +560,10 @@ gtk_calendar_init (GtkCalendar *calendar)
time_t secs; time_t secs;
struct tm *tm; struct tm *tm;
gint i; gint i;
char buffer[255];
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
wchar_t wbuffer[100]; wchar_t wbuffer[100];
#else #else
char buffer[255];
time_t tmp_time; time_t tmp_time;
#endif #endif
GtkCalendarPrivate *priv; GtkCalendarPrivate *priv;
@ -591,23 +591,11 @@ gtk_calendar_init (GtkCalendar *calendar)
strftime ( buffer, sizeof (buffer), "%a", gmtime (&tmp_time)); strftime ( buffer, sizeof (buffer), "%a", gmtime (&tmp_time));
default_abbreviated_dayname[i] = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL); default_abbreviated_dayname[i] = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
#else #else
if (G_WIN32_HAVE_WIDECHAR_API ()) if (!GetLocaleInfoW (GetThreadLocale (), LOCALE_SABBREVDAYNAME1 + (i+6)%7,
{ wbuffer, G_N_ELEMENTS (wbuffer)))
if (!GetLocaleInfoW (GetThreadLocale (), LOCALE_SABBREVDAYNAME1 + (i+6)%7, default_abbreviated_dayname[i] = g_strdup_printf ("(%d)", i);
wbuffer, G_N_ELEMENTS (wbuffer)))
default_abbreviated_dayname[i] = g_strdup_printf ("(%d)", i);
else
default_abbreviated_dayname[i] = g_utf16_to_utf8 (wbuffer, -1, NULL, NULL, NULL);
}
else else
{ default_abbreviated_dayname[i] = g_utf16_to_utf8 (wbuffer, -1, NULL, NULL, NULL);
if (!GetLocaleInfoA (GetThreadLocale (),
(LOCALE_SABBREVDAYNAME1 + (i+6)%7) | LOCALE_USE_CP_ACP,
buffer, G_N_ELEMENTS (buffer)))
default_abbreviated_dayname[i] = g_strdup_printf ("(%d)", i);
else
default_abbreviated_dayname[i] = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
}
#endif #endif
} }
@ -619,23 +607,11 @@ gtk_calendar_init (GtkCalendar *calendar)
strftime ( buffer, sizeof (buffer), "%B", gmtime (&tmp_time)); strftime ( buffer, sizeof (buffer), "%B", gmtime (&tmp_time));
default_monthname[i] = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL); default_monthname[i] = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
#else #else
if (G_WIN32_HAVE_WIDECHAR_API ()) if (!GetLocaleInfoW (GetThreadLocale (), LOCALE_SMONTHNAME1 + i,
{ wbuffer, G_N_ELEMENTS (wbuffer)))
if (!GetLocaleInfoW (GetThreadLocale (), LOCALE_SMONTHNAME1 + i, default_monthname[i] = g_strdup_printf ("(%d)", i);
wbuffer, G_N_ELEMENTS (wbuffer)))
default_monthname[i] = g_strdup_printf ("(%d)", i);
else
default_monthname[i] = g_utf16_to_utf8 (wbuffer, -1, NULL, NULL, NULL);
}
else else
{ default_monthname[i] = g_utf16_to_utf8 (wbuffer, -1, NULL, NULL, NULL);
if (!GetLocaleInfoA (GetThreadLocale (),
(LOCALE_SMONTHNAME1 + i) | LOCALE_USE_CP_ACP,
buffer, G_N_ELEMENTS (buffer)))
default_monthname[i] = g_strdup_printf ("(%d)", i);
else
default_monthname[i] = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
}
#endif #endif
} }
@ -698,6 +674,32 @@ gtk_calendar_init (GtkCalendar *calendar)
else if (strcmp (year_before, "calendar:MY") != 0) else if (strcmp (year_before, "calendar:MY") != 0)
g_warning ("Whoever translated calendar:MY did so wrongly.\n"); g_warning ("Whoever translated calendar:MY did so wrongly.\n");
#ifdef G_OS_WIN32
/* Check if any of those environment variables that affect the
* behaviour of gettext are set. If not, we use the thread's
* locale's week start day.
*/
if (getenv ("LANGUAGE") == NULL &&
getenv ("LC_ALL") == NULL &&
getenv ("LC_MESSAGES") == NULL &&
getenv ("LANG") == NULL)
{
priv->week_start = 0;
week_start = NULL;
if (GetLocaleInfoW (GetThreadLocale (), LOCALE_IFIRSTDAYOFWEEK,
wbuffer, G_N_ELEMENTS (wbuffer)))
week_start = g_utf16_to_utf8 (wbuffer, -1, NULL, NULL, NULL);
if (week_start != NULL)
{
priv->week_start = (week_start[0] - '0' + 1) % 7;
g_free(week_start);
}
}
else
{
#endif
#ifdef HAVE__NL_TIME_FIRST_WEEKDAY #ifdef HAVE__NL_TIME_FIRST_WEEKDAY
langinfo = nl_langinfo (_NL_TIME_FIRST_WEEKDAY); langinfo = nl_langinfo (_NL_TIME_FIRST_WEEKDAY);
first_weekday = langinfo[0]; first_weekday = langinfo[0];
@ -729,6 +731,9 @@ gtk_calendar_init (GtkCalendar *calendar)
priv->week_start = 0; priv->week_start = 0;
} }
#endif #endif
#ifdef G_OS_WIN32
}
#endif
calendar_compute_days (calendar); calendar_compute_days (calendar);
} }