Use code adapted from boost::locale to implement locale name parsing and .mo file reading ourselves. Together with #132142 this removes the last direct Blender dependency on Boost. Pull Request: https://projects.blender.org/blender/blender/pulls/133347
47 lines
1.1 KiB
Plaintext
47 lines
1.1 KiB
Plaintext
/* SPDX-FileCopyrightText: 2012 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
/** \file
|
|
* \ingroup intern_locale
|
|
*/
|
|
|
|
#include "messages.h"
|
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
#include <cstdlib>
|
|
#include <string>
|
|
|
|
namespace blender::locale {
|
|
|
|
#if !defined(WITH_HEADLESS) && !defined(WITH_GHOST_SDL)
|
|
/* Get current locale. */
|
|
std::string Info::macos_user_locale()
|
|
{
|
|
std::string result;
|
|
|
|
@autoreleasepool {
|
|
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 #88877. */
|
|
// NSString *nsIdentifier = [myNSLocale localeIdentifier];
|
|
|
|
NSString *nsIdentifier = myNSLocale.languageCode;
|
|
NSString *nsIdentifier_country = myNSLocale.countryCode;
|
|
if (nsIdentifier.length != 0 && nsIdentifier_country.length != 0) {
|
|
nsIdentifier = [NSString stringWithFormat:@"%@_%@", nsIdentifier, nsIdentifier_country];
|
|
}
|
|
|
|
result = nsIdentifier.UTF8String;
|
|
}
|
|
|
|
return result + ".UTF-8";
|
|
}
|
|
#endif
|
|
|
|
} // namespace blender::locale
|