get_language: New function
authorJohn Darrington <john@darrington.wattle.id.au>
Sun, 5 Jul 2020 06:12:41 +0000 (08:12 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Wed, 19 Aug 2020 06:53:33 +0000 (08:53 +0200)
Smake
src/libpspp/i18n.c
src/libpspp/i18n.h

diff --git a/Smake b/Smake
index f73e4f5a09cb74e64a9fabbf3904a6adf65379f9..caae02fd97718c881cd5bf6ef95f978b707a3fe7 100644 (file)
--- a/Smake
+++ b/Smake
@@ -66,6 +66,7 @@ GNULIB_MODULES = \
        intprops \
        inttostr \
        localcharset \
+       localename \
         mbchar \
         mbiter \
        memcasecmp \
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.
index ea16cfe0fa98dc01db0440e2f4d4cfe85863fd8a..232c5dc166ec69d6e68e0c4ac1fe9d10fe6e7dae 100644 (file)
@@ -169,4 +169,8 @@ struct encoding_category
 struct encoding_category *get_encoding_categories (void);
 size_t get_n_encoding_categories (void);
 
+/* Return the ISO two letter code for the current LC_MESSAGES
+   locale category.  */
+char *get_language (void);
+
 #endif /* i18n.h */