Improvements for handling default locale under macOS and Unix. See #23119, #23147, #23226. Closes #23114.