get_language: New function
[pspp] / src / libpspp / i18n.c
index fe749dff181cda0b6144010f74c171d97870a49a..31f07ed8da0234d24bf8e53b5b77f377098ebaeb 100644 (file)
@@ -40,6 +40,7 @@
 #include "gl/c-ctype.h"
 #include "gl/c-strcase.h"
 #include "gl/localcharset.h"
+#include <gl/localename.h>
 #include "gl/minmax.h"
 #include "gl/xalloc.h"
 #include "gl/relocatable.h"
@@ -665,6 +666,21 @@ set_default_encoding (const char *enc)
   default_encoding = xstrdup (enc);
 }
 
+/* Return the ISO two letter code for the current LC_MESSAGES
+   locale category.  */
+char *
+get_language (void)
+{
+  const char *localename = gl_locale_name (LC_MESSAGES, "LC_MESSAGES");
+  if (0 == strcmp (localename, "C"))
+    return NULL;
+  char *ln = xstrdup (localename);
+  char *end = strchr (ln, '_');
+  if (end)
+    *end = '\0';
+  return ln;
+}
+
 
 /* Attempts to set the encoding from a locale name
    returns true if successful.