-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Detect the default locale name during startup on Apple platforms #68706
Changes from 7 commits
2f780a4
4741f33
f5adcfd
8db8113
82f4e62
5f034bc
5f367d5
28cd339
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#include <stdlib.h> | ||
#include "pal_locale_internal.h" | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
char* DetectDefaultAppleLocaleName() | ||
{ | ||
NSLocale *currentLocale = [NSLocale currentLocale]; | ||
NSString *localeName = @""; | ||
|
||
if (!currentLocale) | ||
{ | ||
return strdup([localeName UTF8String]); | ||
} | ||
|
||
if ([currentLocale.languageCode length] > 0 && [currentLocale.countryCode length] > 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's possible if it grabs the https://developer.apple.com/documentation/foundation/nslocale/1416263-localeidentifier?language=objc There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great, I would suggest getting |
||
{ | ||
localeName = [NSString stringWithFormat:@"%@-%@", currentLocale.languageCode, currentLocale.countryCode]; | ||
} | ||
else | ||
{ | ||
localeName = [currentLocale.localeIdentifier stringByReplacingOccurrencesOfString:@"_" withString:@"-"]; | ||
steveisok marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
return strdup([localeName UTF8String]); | ||
akoeplinger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this not going to pass on windows and Linux too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is possible to fail on Linux and Windows. On Windows it is unlikely the users will set the user locale to Invariant but it is possible. For Linux, some distros set the locale to "C" which we replace it with Invariant. That means it is likely to fail on Linux.