[PATCH 3/3] [win32] set default locale to "English" in statistics.c

Lubomir I. Ivanov neolit123 at gmail.com
Thu Nov 3 13:44:06 PDT 2011

From: "Lubomir I. Ivanov" <neolit123 at gmail.com>

sets the default locale to "English" in statistics.c for win32.
it seems that mingw/GTK outputs xxxxxx, xxxxx characters
for Day, Month (%a, %b) on a non english locale Windows system
until 'setlocale(LC_ALL, "English")' is specified.
pending for a better fix perhaps, yet all units
might need to be translated as well, following this logic
- e.g. cyrilic "m" for meters and "kg" for kilograms.
uses _tsetlocale for eventual unicode support on win32.

Signed-off-by: Lubomir I. Ivanov <neolit123 at gmail.com>
 statistics.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/statistics.c b/statistics.c
index 8000309..d59d645 100644
--- a/statistics.c
+++ b/statistics.c
@@ -19,6 +19,12 @@
 #include "display-gtk.h"
 #include "divelist.h"
+/* use "English" as the default locale on windows */
+#ifdef WIN32
+#include <locale.h>
+#include <tchar.h>
 typedef struct {
 	GtkWidget *date,
@@ -127,8 +133,12 @@ void show_dive_stats(struct dive *dive)
 	struct dive *prev_dive;
 	process_all_dives(dive, &prev_dive);
+	#ifdef WIN32
+	_tsetlocale(LC_ALL, "English");
+	#endif
-	strftime(buf, 80, "%a, %b %d, %Y, %k:%M", gmtime(&dive->when));
+	strftime(buf, 80, "%a, %b %d, %Y, %H:%M", gmtime(&dive->when));
 	set_label(info_stat_w.date, buf);
 	set_label(info_stat_w.dive_time, "%d min", (dive->duration.seconds + 30) / 60);
 	if (prev_dive)

More information about the subsurface mailing list