2023-08-15 14:20:26 +00:00
|
|
|
/* SPDX-FileCopyrightText: 2012 Blender Authors
|
2023-06-15 03:09:04 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2022-02-11 03:56:03 +00:00
|
|
|
|
2014-10-07 20:46:19 +00:00
|
|
|
#include "boost_locale_wrapper.h"
|
|
|
|
|
2021-12-14 07:35:31 +00:00
|
|
|
/** \file
|
|
|
|
* \ingroup intern_locale
|
|
|
|
*/
|
|
|
|
|
2014-10-07 20:46:19 +00:00
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
|
|
static char *user_locale = NULL;
|
|
|
|
|
|
|
|
// get current locale
|
|
|
|
const char *osx_user_locale()
|
|
|
|
{
|
|
|
|
::free(user_locale);
|
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
CFLocaleRef myCFLocale = CFLocaleCopyCurrent();
|
|
|
|
NSLocale *myNSLocale = (NSLocale *)myCFLocale;
|
|
|
|
[myNSLocale autorelease];
|
2021-10-29 08:11:04 +00:00
|
|
|
|
|
|
|
// This produces gettext-invalid locale in recent macOS versions (11.4),
|
2023-02-12 03:37:16 +00:00
|
|
|
// like `ko-Kore_KR` instead of `ko_KR`. See #88877.
|
2021-10-29 08:11:04 +00:00
|
|
|
// NSString *nsIdentifier = [myNSLocale localeIdentifier];
|
|
|
|
|
|
|
|
const NSString *nsIdentifier = [myNSLocale languageCode];
|
|
|
|
const NSString *const nsIdentifier_country = [myNSLocale countryCode];
|
|
|
|
if ([nsIdentifier length] != 0 && [nsIdentifier_country length] != 0) {
|
|
|
|
nsIdentifier = [NSString stringWithFormat:@"%@_%@", nsIdentifier, nsIdentifier_country];
|
|
|
|
}
|
|
|
|
|
2014-10-07 20:46:19 +00:00
|
|
|
user_locale = ::strdup([nsIdentifier UTF8String]);
|
|
|
|
[pool drain];
|
|
|
|
|
|
|
|
return user_locale;
|
|
|
|
}
|