set LC_ALL from macOS locale so that setlocale(2) will work

This commit is contained in:
Paul Davis
2020-05-01 12:32:38 -06:00
parent 6479a1c9d5
commit 0486fe3e7d

View File

@@ -122,16 +122,19 @@ set_language_preference ()
}
}
/* now get AppleLocale value and use that for LANG */
/* now get AppleLocale value and use that to set LC_ALL because Launchd-started processes (i.e. GUI apps)
do not have this environment variable set, and without it, setlocale (LC_ALL, "") will fail.
Note that it doesn't matter much what we set LC_ALL to for gettext's purposes, but other aspects of the
locale system do need a value that mostly/sort-of/kind-of represents the user's own preferences. So, get
that from CoreFoundation APIs.
*/
CFLocaleRef cflocale = CFLocaleCopyCurrent();
NSString* nslocale = (NSString*) CFLocaleGetValue (cflocale, kCFLocaleIdentifier);
/* the full POSIX locale specification allows for lots of things. that could be an issue. Silly Apple.
*/
cout << "LANG set to " << [nslocale UTF8String] << endl;
setenv ("LANG", [nslocale UTF8String], 0);
cout << "Apple's CoreFoundation API says that this user's locale is " << [nslocale UTF8String] << endl;
setenv ("LC_ALL", [nslocale UTF8String], 0);
CFRelease (cflocale);
}