// Courtesy of ChatGPT ​ // Link against the Core Foundation framework by passing `-framework CoreFoundation` to the compiler ​ #include #include #include ​ int main() { CFLocaleRef localeRef = CFLocaleCopyCurrent(); CFStringRef languageCodeRef = CFLocaleGetValue(localeRef, kCFLocaleLanguageCode); CFIndex bufferSize = CFStringGetLength(languageCodeRef) + 1; char* languageCode = new char[bufferSize]; CFStringGetCString(languageCodeRef, languageCode, bufferSize, kCFStringEncodingUTF8); std::string result = languageCode; delete[] languageCode; std::cout << "User's locale: " << result << std::endl; CFRelease(localeRef); return 0; }