Blender V5.0
messages_apple.mm
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2012 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "messages.hh"
10
11#import <Cocoa/Cocoa.h>
12
13#include <cstdlib>
14#include <string>
15
16namespace blender::locale {
17
18#if !defined(WITH_HEADLESS) && !defined(WITH_GHOST_SDL)
19/* Get current locale. */
20std::string macos_user_locale()
21{
22 std::string result;
23
24 @autoreleasepool {
25 CFLocaleRef myCFLocale = CFLocaleCopyCurrent();
26 NSLocale *myNSLocale = (NSLocale *)myCFLocale;
27 [myNSLocale autorelease];
28
29 /* This produces gettext-invalid locale in recent macOS versions (11.4),
30 * like `ko-Kore_KR` instead of `ko_KR`. See #88877. */
31 // NSString *nsIdentifier = [myNSLocale localeIdentifier];
32
33 NSString *nsIdentifier = myNSLocale.languageCode;
34 NSString *nsIdentifier_country = myNSLocale.countryCode;
35 if (nsIdentifier.length != 0 && nsIdentifier_country.length != 0) {
36 nsIdentifier = [NSString stringWithFormat:@"%@_%@", nsIdentifier, nsIdentifier_country];
37 }
38
39 result = nsIdentifier.UTF8String;
40 }
41
42 return result + ".UTF-8";
43}
44#endif
45
46} // namespace blender::locale
std::string macos_user_locale()