mirror of
https://github.com/neovim/neovim.git
synced 2025-10-12 21:06:13 +00:00
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
This commit is contained in:
40
src/nvim/os/lang.c
Normal file
40
src/nvim/os/lang.c
Normal file
@@ -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
|
||||
}
|
Reference in New Issue
Block a user