Skip to content

Commit 6061b2c

Browse files
[release/9.0-staging] [iOS] Retrieve device locale in full (specific) format from ObjectiveC APIs (#111612)
1 parent ea5e814 commit 6061b2c

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/libraries/System.Runtime/tests/System.Globalization.Tests/CultureInfo/CultureInfoCurrentCulture.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ public void CurrentCulture_Default_Not_Invariant()
4444
Assert.NotEqual(CultureInfo.CurrentUICulture, CultureInfo.InvariantCulture);
4545
}
4646

47+
[Fact]
48+
[PlatformSpecific(TestPlatforms.OSX | TestPlatforms.iOS | TestPlatforms.MacCatalyst | TestPlatforms.tvOS)]
49+
[SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.MacCatalyst | TestPlatforms.tvOS, "https://github.com/dotnet/runtime/issues/111501")]
50+
public void CurrentCulture_Default_Is_Specific()
51+
{
52+
// On OSX-like platforms, the current culture taken from default system culture should be specific.
53+
Assert.False(CultureInfo.CurrentCulture.IsNeutralCulture);
54+
}
55+
4756
[Fact]
4857
public void CurrentCulture_Set_Null_ThrowsArgumentNullException()
4958
{

src/native/libs/System.Globalization.Native/pal_locale.m

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -786,21 +786,14 @@ int32_t GlobalizationNative_GetLocalesNative(UChar* value, int32_t length)
786786
}
787787
}
788788

789-
static NSString* GetBaseName(NSString *localeIdentifier)
790-
{
791-
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:localeIdentifier];
792-
NSString *languageCode = [locale objectForKey:NSLocaleLanguageCode];
793-
return languageCode;
794-
}
795-
796789
const char* GlobalizationNative_GetDefaultLocaleNameNative(void)
797790
{
798791
@autoreleasepool
799792
{
800793
if (NSLocale.preferredLanguages.count > 0)
801794
{
802795
NSString *preferredLanguage = [NSLocale.preferredLanguages objectAtIndex:0];
803-
return strdup([GetBaseName(preferredLanguage) UTF8String]);
796+
return strdup([preferredLanguage UTF8String]);
804797
}
805798
else
806799
{
@@ -821,7 +814,7 @@ int32_t GlobalizationNative_GetLocalesNative(UChar* value, int32_t length)
821814
localeName = currentLocale.localeIdentifier;
822815
}
823816

824-
return strdup([GetBaseName(localeName) UTF8String]);
817+
return strdup([localeName UTF8String]);
825818
}
826819
}
827820
}

0 commit comments

Comments
 (0)