Welcome to mirror list, hosted at ThFree Co, Russian Federation.

osx_user_locale.mm « locale « intern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ce694b5fc1e59563d93279a2c0383293a0257d8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "boost_locale_wrapper.h"

#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];

  // This produces gettext-invalid locale in recent macOS versions (11.4),
  // like `ko-Kore_KR` instead of `ko_KR`. See T88877.
  // 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];
  }

  user_locale = ::strdup([nsIdentifier UTF8String]);
  [pool drain];

  return user_locale;
}