From bea279dad74479d86671f3acdc8c945d3ce5f2be Mon Sep 17 00:00:00 2001 From: John Darrington Date: Sun, 5 Jul 2020 08:12:41 +0200 Subject: [PATCH] get_language: New function --- Smake | 1 + src/libpspp/i18n.c | 16 ++++++++++++++++ src/libpspp/i18n.h | 4 ++++ 3 files changed, 21 insertions(+) diff --git a/Smake b/Smake index f73e4f5a09..caae02fd97 100644 --- a/Smake +++ b/Smake @@ -66,6 +66,7 @@ GNULIB_MODULES = \ intprops \ inttostr \ localcharset \ + localename \ mbchar \ mbiter \ memcasecmp \ diff --git a/src/libpspp/i18n.c b/src/libpspp/i18n.c index fe749dff18..31f07ed8da 100644 --- a/src/libpspp/i18n.c +++ b/src/libpspp/i18n.c @@ -40,6 +40,7 @@ #include "gl/c-ctype.h" #include "gl/c-strcase.h" #include "gl/localcharset.h" +#include #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. diff --git a/src/libpspp/i18n.h b/src/libpspp/i18n.h index ea16cfe0fa..232c5dc166 100644 --- a/src/libpspp/i18n.h +++ b/src/libpspp/i18n.h @@ -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 */ -- 2.30.2