Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ public static IEnumerable<object[]> Ctor_String_TestData()
yield return new object[] { "nb-NO", new [] { "nb-NO" } };
yield return new object[] { "ne", new [] { "ne" }};
yield return new object[] { "ne-NP", new [] { "ne-NP" }};
yield return new object[] { "no", new [] { "no" } };
yield return new object[] { "nl", new [] { "nl" } };
yield return new object[] { "nl-BE", new [] { "nl-BE" } };
yield return new object[] { "nl-NL", new [] { "nl-NL" } };
Expand Down Expand Up @@ -366,7 +367,6 @@ public static IEnumerable<object[]> Ctor_String_TestData()
yield return new object[] { "ha-Latn", new [] { "ha-Latn" }};
yield return new object[] { "ha-Latn-NG", new [] { "ha-Latn-NG" }};
yield return new object[] { "mn-Cyrl", new [] { "mn-Cyrl" }};
yield return new object[] { "no", new [] { "no" } };
yield return new object[] { "sr-Cyrl", new [] { "sr-Cyrl" } };
yield return new object[] { "sr-Cyrl-BA", new [] { "sr-Cyrl-BA" }};
yield return new object[] { "sr-Cyrl-CS", new [] { "sr-Cyrl-CS" }};
Expand Down Expand Up @@ -441,6 +441,19 @@ public void Ctor_String(string name, string[] expectedNames)
Assert.Equal(cultureName, culture.ToString(), ignoreCase: true);
}

[Theory]
[InlineData("no", "no", "no", "nor", "")]
[InlineData("no-NO", "no-NO", "no", "nor", "no")]
public void Ctor_String_NorwegianLanguageNames(string name, string expectedName, string expectedTwoLetterName, string expectedThreeLetterName, string expectedParentName)
{
CultureInfo culture = new CultureInfo(name);

Assert.Equal(expectedName, culture.Name);
Assert.Equal(expectedTwoLetterName, culture.TwoLetterISOLanguageName);
Assert.Equal(expectedThreeLetterName, culture.ThreeLetterISOLanguageName);
Assert.Equal(expectedParentName, culture.Parent.Name);
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotHybridGlobalizationOnApplePlatform))]
public void Ctor_String_Invalid()
{
Expand Down
58 changes: 51 additions & 7 deletions src/native/libs/System.Globalization.Native/pal_locale.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,56 @@
}

#if defined(APPLE_HYBRID_GLOBALIZATION)

static NSString* GetLanguageSubtag(NSString *localeName)
{
NSRange separatorRange = [localeName rangeOfCharacterFromSet:
[NSCharacterSet characterSetWithCharactersInString:@"-_@"]];
if (separatorRange.location != NSNotFound)
return [localeName substringToIndex:separatorRange.location];
return localeName;
}

static NSString* GetLocaleLanguageCode(NSString *localeName, NSLocale *canonicalLocale)
{
NSString *languageSubtag = GetLanguageSubtag(localeName);
if ([languageSubtag caseInsensitiveCompare:@"no"] == NSOrderedSame &&
[canonicalLocale.languageCode isEqualToString:@"nb"])
{
return @"no";
}
Comment thread
matouskozak marked this conversation as resolved.

return canonicalLocale.languageCode;
}

static NSString* GetLocaleIdentifier(NSString *localeName, NSLocale *canonicalLocale)
{
NSString *canonicalLanguageCode = canonicalLocale.languageCode;
NSString *languageCode = GetLocaleLanguageCode(localeName, canonicalLocale);
NSString *localeIdentifier = canonicalLocale.localeIdentifier;

if (languageCode == nil ||
canonicalLanguageCode == nil ||
[languageCode isEqualToString:canonicalLanguageCode])
{
return localeIdentifier;
}

return [languageCode stringByAppendingString:[localeIdentifier substringFromIndex:canonicalLanguageCode.length]];
}
Comment thread
matouskozak marked this conversation as resolved.
Comment thread
matouskozak marked this conversation as resolved.

const char* GlobalizationNative_GetLocaleNameNative(const char* localeName)
{
@autoreleasepool
{
NSString *locName = [[NSString alloc] initWithUTF8String:localeName];
NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName];
const char* value = [currentLocale.localeIdentifier UTF8String];
return strdup(value);
NSString *value = GetLocaleIdentifier(locName, currentLocale);

if (value.length == 0)
return strdup("");

return strdup([value UTF8String]);
}
}

Expand Down Expand Up @@ -238,12 +280,14 @@ static int16_t _findIndex(const char* const* list, const char* key)
value = numberFormatter.minusSign;
break;
case LocaleString_Iso639LanguageTwoLetterName:
value = [currentLocale objectForKey:NSLocaleLanguageCode];
{
value = GetLocaleLanguageCode(locName, currentLocale);
break;
}
case LocaleString_Iso639LanguageThreeLetterName:
{
NSString *iso639_2 = [currentLocale objectForKey:NSLocaleLanguageCode];
return iso639_2 == nil ? strdup("") : strdup(getISO3LanguageByLangCode([iso639_2 UTF8String]));
NSString *languageCode = GetLocaleLanguageCode(locName, currentLocale);
return languageCode == nil ? strdup("") : strdup(getISO3LanguageByLangCode([languageCode UTF8String]));
}
case LocaleString_Iso3166CountryName:
value = [currentLocale objectForKey:NSLocaleCountryCode];
Expand Down Expand Up @@ -271,7 +315,8 @@ static int16_t _findIndex(const char* const* list, const char* key)
case LocaleString_ParentName:
{
char localeNameTemp[FULLNAME_CAPACITY];
const char* lName = [currentLocale.localeIdentifier UTF8String];
NSString *localeIdentifier = GetLocaleIdentifier(locName, currentLocale);
const char* lName = [localeIdentifier UTF8String];
GetParent(lName, localeNameTemp, FULLNAME_CAPACITY);
return strdup(localeNameTemp);
}
Expand Down Expand Up @@ -839,4 +884,3 @@ int32_t GlobalizationNative_IsPredefinedLocaleNative(const char* localeName)
}
}
#endif

Loading