-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[release/6.0] Detect the default locale name during startup on Apple …
…platforms (#68934) * Detect the default locale name during startup on Apple platforms This change adds a function to lookup the current NSLocale and extract the language + country code to load into ICU by default. Previously, we would defer to uloc_getDefault in ICU, which would return a value we would ignore (en_US_POSIX) and result in falling back to invariant mode. Fixes #68321 * Link in foundation and address feedback * Link in foundation in coreclr * Check LANG env variable first * Defer to icu first, since it's looking for LANG and certain values. * #ifdef not #if * PR feedback * Remove redundant string replace * pal_locale.m needs to be in a different location than upstream * cmake tweak to make sure foundation gets linked in Co-authored-by: Steve Pfister <steve.pfister@microsoft.com>
- Loading branch information
1 parent
6a2204c
commit 86308dc
Showing
7 changed files
with
115 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/libraries/Native/Unix/System.Globalization.Native/pal_locale.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
{ | ||
localeName = [NSString stringWithFormat:@"%@-%@", currentLocale.languageCode, currentLocale.countryCode]; | ||
} | ||
else | ||
{ | ||
localeName = currentLocale.localeIdentifier; | ||
} | ||
|
||
return strdup([localeName UTF8String]); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters