Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libraries/Common/src/Interop/Interop.Locale.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal static partial class Globalization
internal static partial string GetDefaultLocaleNameNative();

[LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleInfoStringNative", StringMarshalling = StringMarshalling.Utf8)]
internal static partial string GetLocaleInfoStringNative(string localeName, uint localeStringData);
internal static partial string GetLocaleInfoStringNative(string localeName, uint localeStringData, string? uiLocaleName = null);

[LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleInfoIntNative", StringMarshalling = StringMarshalling.Utf8)]
internal static partial int GetLocaleInfoIntNative(string localeName, uint localeNumberData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,12 @@ internal string DisplayName

private string GetLanguageDisplayNameCore(string cultureName) => GlobalizationMode.UseNls ?
NlsGetLanguageDisplayName(cultureName) :
#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS
GlobalizationMode.Hybrid ? GetLocaleInfoNative(cultureName, LocaleStringData.LocalizedDisplayName, CultureInfo.CurrentUICulture.Name) :
IcuGetLanguageDisplayName(cultureName);
#else
IcuGetLanguageDisplayName(cultureName);
#endif

/// <summary>
/// English pretty name for this locale (ie: English (United States))
Expand Down Expand Up @@ -2371,7 +2376,7 @@ private string GetLocaleInfoCore(LocaleStringData type, string? uiCultureName =
return null!;

#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS
return GlobalizationMode.Hybrid ? GetLocaleInfoNative(type) : IcuGetLocaleInfo(type, uiCultureName);
return GlobalizationMode.Hybrid ? GetLocaleInfoNative(type, uiCultureName) : IcuGetLocaleInfo(type, uiCultureName);
#else
return GlobalizationMode.UseNls ? NlsGetLocaleInfo(type) : IcuGetLocaleInfo(type, uiCultureName);
#endif
Expand All @@ -2384,7 +2389,7 @@ private string GetLocaleInfoCore(string localeName, LocaleStringData type, strin
return null!;

#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS
return GlobalizationMode.Hybrid ? GetLocaleInfoNative(localeName, type) : IcuGetLocaleInfo(localeName, type, uiCultureName);
return GlobalizationMode.Hybrid ? GetLocaleInfoNative(localeName, type, uiCultureName) : IcuGetLocaleInfo(localeName, type, uiCultureName);
#else
return GlobalizationMode.UseNls ? NlsGetLocaleInfo(localeName, type) : IcuGetLocaleInfo(localeName, type, uiCultureName);
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ internal static string GetLocaleNameNative(string localeName)
return Interop.Globalization.GetLocaleNameNative(localeName);
}

private string GetLocaleInfoNative(LocaleStringData type)
private string GetLocaleInfoNative(LocaleStringData type, string? uiLocaleName = null)
{
Debug.Assert(!GlobalizationMode.Invariant);
Debug.Assert(_sWindowsName != null, "[CultureData.GetLocaleInfoNative] Expected _sWindowsName to be populated already");

return GetLocaleInfoNative(_sWindowsName, type);
return GetLocaleInfoNative(_sWindowsName, type, uiLocaleName);
}

// For LOCALE_SPARENT we need the option of using the "real" name (forcing neutral names) instead of the
// "windows" name, which can be specific for downlevel (< windows 7) os's.
private static string GetLocaleInfoNative(string localeName, LocaleStringData type)
private static string GetLocaleInfoNative(string localeName, LocaleStringData type, string? uiLocaleName = null)
{
Debug.Assert(localeName != null, "[CultureData.GetLocaleInfoNative] Expected localeName to be not be null");

return Interop.Globalization.GetLocaleInfoStringNative(localeName, (uint)type);
return Interop.Globalization.GetLocaleInfoStringNative(localeName, (uint)type, uiLocaleName);
}

private int GetLocaleInfoNative(LocaleNumberData type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace System.Globalization.Tests
{
public class CultureInfoNames
{
private static bool SupportFullIcuResources => PlatformDetection.IsNotMobile && PlatformDetection.IsIcuGlobalization;
private static bool SupportFullIcuResources => (PlatformDetection.IsNotMobile && PlatformDetection.IsIcuGlobalization) || PlatformDetection.IsHybridGlobalizationOnOSX;

[ConditionalTheory(nameof(SupportFullIcuResources))]
[InlineData("en", "en", "English", "English")]
Expand Down
47 changes: 33 additions & 14 deletions src/native/libs/System.Globalization.Native/pal_locale.m
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ static int16_t _findIndex(const char* const* list, const char* key)
return LANGUAGES_3[offset];
}

const char* GlobalizationNative_GetLocaleInfoStringNative(const char* localeName, LocaleStringData localeStringData)
const char* GlobalizationNative_GetLocaleInfoStringNative(const char* localeName, LocaleStringData localeStringData, const char* currentUILocaleName)
{
@autoreleasepool
{
Expand All @@ -152,6 +152,12 @@ static int16_t _findIndex(const char* const* list, const char* key)
{
///// <summary>localized name of locale, eg "German (Germany)" in UI language (corresponds to LOCALE_SLOCALIZEDDISPLAYNAME)</summary>
case LocaleString_LocalizedDisplayName:
{
NSString *currUILocaleName = [NSString stringWithFormat:@"%s", currentUILocaleName == NULL ? GlobalizationNative_GetDefaultLocaleNameNative() : currentUILocaleName];
NSLocale *currentUILocale = [[NSLocale alloc] initWithLocaleIdentifier:currUILocaleName];
value = [currentUILocale displayNameForKey:NSLocaleIdentifier value:currentLocale.localeIdentifier];
break;
}
/// <summary>Display name (language + country usually) in English, eg "German (Germany)" (corresponds to LOCALE_SENGLISHDISPLAYNAME)</summary>
case LocaleString_EnglishDisplayName:
value = [gbLocale displayNameForKey:NSLocaleIdentifier value:currentLocale.localeIdentifier];
Expand All @@ -162,6 +168,12 @@ static int16_t _findIndex(const char* const* list, const char* key)
break;
/// <summary>Language Display Name for a language, eg "German" in UI language (corresponds to LOCALE_SLOCALIZEDLANGUAGENAME)</summary>
case LocaleString_LocalizedLanguageName:
{
NSString *currUILocaleName = [NSString stringWithFormat:@"%s", currentUILocaleName == NULL ? GlobalizationNative_GetDefaultLocaleNameNative() : currentUILocaleName];
NSLocale *currentUILocale = [[NSLocale alloc] initWithLocaleIdentifier:currUILocaleName];
value = [currentUILocale localizedStringForLanguageCode:currentLocale.languageCode];
break;
}
/// <summary>English name of language, eg "German" (corresponds to LOCALE_SENGLISHLANGUAGENAME)</summary>
case LocaleString_EnglishLanguageName:
value = [gbLocale localizedStringForLanguageCode:currentLocale.languageCode];
Expand Down Expand Up @@ -781,24 +793,31 @@ int32_t GlobalizationNative_GetLocalesNative(UChar* value, int32_t length)
{
@autoreleasepool
{
NSLocale *currentLocale = [NSLocale currentLocale];
NSString *localeName = @"";

if (!currentLocale)
{
return strdup([localeName UTF8String]);
}

if ([currentLocale.languageCode length] > 0 && [currentLocale.countryCode length] > 0)
if (NSLocale.preferredLanguages.count > 0)
Comment thread
mdh1418 marked this conversation as resolved.
{
localeName = [NSString stringWithFormat:@"%@-%@", currentLocale.languageCode, currentLocale.countryCode];
return strdup([NSLocale.preferredLanguages[0] UTF8String]);
}
else
{
localeName = currentLocale.localeIdentifier;
}
NSLocale *currentLocale = [NSLocale currentLocale];
NSString *localeName = @"";

return strdup([localeName UTF8String]);
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]);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ PALEXPORT int32_t GlobalizationNative_GetLocaleInfoString(const UChar* localeNam
const UChar* uiLocaleName);

#ifdef __APPLE__
PALEXPORT const char* GlobalizationNative_GetLocaleInfoStringNative(const char* localeName, LocaleStringData localeStringData);
PALEXPORT const char* GlobalizationNative_GetLocaleInfoStringNative(const char* localeName, LocaleStringData localeStringData, const char* currentUILocaleName);
#endif