diff options
author | James McCoy <jamessan@jamessan.com> | 2017-12-07 20:53:02 -0500 |
---|---|---|
committer | James McCoy <jamessan@jamessan.com> | 2017-12-10 07:45:04 -0500 |
commit | 1f2b35860f755513a58c1d010f082d946c889b47 (patch) | |
tree | 90b236c1244a29ff4d407fb6e2bc47fa7929e254 /src/nvim/os | |
parent | 4a5bc6275d09056ff0ccf5a29a878d48bbe58655 (diff) | |
download | rneovim-1f2b35860f755513a58c1d010f082d946c889b47.tar.gz rneovim-1f2b35860f755513a58c1d010f082d946c889b47.tar.bz2 rneovim-1f2b35860f755513a58c1d010f082d946c889b47.zip |
mac: Set $LANG based on the system locale
Unix's typical locale-related environment variables aren't always set
appropriately on a Mac. Instead of relying on them, query the locale
information using Mac specific APIs and then set $LANG appropriately for
the rest of nvim.
Closes #5873
Diffstat (limited to 'src/nvim/os')
-rw-r--r-- | src/nvim/os/lang.c | 40 | ||||
-rw-r--r-- | src/nvim/os/lang.h | 7 |
2 files changed, 47 insertions, 0 deletions
diff --git a/src/nvim/os/lang.c b/src/nvim/os/lang.c new file mode 100644 index 0000000000..f0bbf4b1cb --- /dev/null +++ b/src/nvim/os/lang.c @@ -0,0 +1,40 @@ +#ifdef __APPLE__ +# define Boolean CFBoolean // Avoid conflict with API's Boolean +# include <CoreFoundation/CFLocale.h> +# include <CoreFoundation/CFString.h> +# undef Boolean +#endif + +#ifdef HAVE_LOCALE_H +# include <locale.h> +#endif +#include "nvim/os/os.h" + +void lang_init(void) +{ +#ifdef __APPLE__ + if (os_getenv("LANG") == NULL) { + CFLocaleRef cf_locale = CFLocaleCopyCurrent(); + CFTypeRef cf_lang_region = CFLocaleGetValue(cf_locale, + kCFLocaleIdentifier); + CFRetain(cf_lang_region); + CFRelease(cf_locale); + + const char *lang_region = CFStringGetCStringPtr(cf_lang_region, + kCFStringEncodingUTF8); + if (lang_region) { + os_setenv("LANG", lang_region, true); + } else { + char buf[20] = { 0 }; + if (CFStringGetCString(cf_lang_region, buf, 20, + kCFStringEncodingUTF8)) { + os_setenv("LANG", lang_region, true); + } + } + CFRelease(cf_lang_region); +# ifdef HAVE_LOCALE_H + setlocale(LC_ALL, ""); +# endif + } +#endif +} diff --git a/src/nvim/os/lang.h b/src/nvim/os/lang.h new file mode 100644 index 0000000000..f60e064f57 --- /dev/null +++ b/src/nvim/os/lang.h @@ -0,0 +1,7 @@ +#ifndef NVIM_OS_LANG_H +#define NVIM_OS_LANG_H + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "os/lang.h.generated.h" +#endif +#endif // NVIM_OS_LANG_H |