diff options
| author | James McCoy <jamessan@jamessan.com> | 2017-12-10 10:47:13 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-12-10 10:47:13 -0500 |
| commit | 6f41ce026005dab1129685f31bce9b85e62fd41f (patch) | |
| tree | 66b8f63e621104792a07b5bd31282923b47f695e /src/nvim/os/lang.c | |
| parent | abe38f7d26d68d7032ea391c039c56c8b87675a5 (diff) | |
| parent | 1f2b35860f755513a58c1d010f082d946c889b47 (diff) | |
| download | rneovim-6f41ce026005dab1129685f31bce9b85e62fd41f.tar.gz rneovim-6f41ce026005dab1129685f31bce9b85e62fd41f.tar.bz2 rneovim-6f41ce026005dab1129685f31bce9b85e62fd41f.zip | |
Merge pull request #7704 from jamessan/mac-lang-fix
mac: Set $LANG based on the system locale
Diffstat (limited to 'src/nvim/os/lang.c')
| -rw-r--r-- | src/nvim/os/lang.c | 40 |
1 files changed, 40 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 +} |
