Refactor locale initialisation.
[pspp-builds.git] / src / libpspp / i18n.c
index 1463a4eecf667e43dd8fcbbedfa35f0d527ad4d4..36215b700c574ee6d9ef69acadc1e684cbde99e5 100644 (file)
@@ -21,6 +21,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <libintl.h>
 #include <iconv.h>
 #include <errno.h>
 #include "assertion.h"
@@ -29,6 +30,8 @@
 
 #include "i18n.h"
 
+#include "version.h"
+
 #include <localcharset.h>
 #include "xstrndup.h"
 
@@ -182,7 +185,19 @@ recode_string (const char *to, const char *from,
 void
 i18n_init (void)
 {
-  free (default_encoding);
+#if ENABLE_NLS
+  setlocale (LC_CTYPE, "");
+#if HAVE_LC_MESSAGES
+  setlocale (LC_MESSAGES, "");
+#endif
+#if HAVE_LC_PAPER
+  setlocale (LC_PAPER, "");
+#endif
+  bindtextdomain (PACKAGE, locale_dir);
+  textdomain (PACKAGE);
+#endif /* ENABLE_NLS */
+
+  assert (default_encoding == NULL);
   default_encoding = strdup (locale_charset ());
 
   hmapx_init (&map);