-
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.
Initial changes for GetLocaleInfoString (#81470)
Initial changes for globalization hybrid mode. Implemented GetLocaleInfoStringName and GetLocaleNameNative for osx platforms.
- Loading branch information
Showing
18 changed files
with
320 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Runtime.InteropServices; | ||
|
||
internal static partial class Interop | ||
{ | ||
internal static partial class Globalization | ||
{ | ||
[LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleNameNative", StringMarshalling = StringMarshalling.Utf8)] | ||
internal static unsafe partial string GetLocaleNameNative(string localeName); | ||
|
||
[LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLocaleInfoStringNative", StringMarshalling = StringMarshalling.Utf8)] | ||
internal static unsafe partial string GetLocaleInfoStringNative(string localeName, uint localeStringData); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/libraries/System.Globalization/tests/Hybrid/Hybrid.Tests.csproj
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,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFrameworks>$(NetCoreAppCurrent)-ios;$(NetCoreAppCurrent)-tvos;$(NetCoreAppCurrent)-maccatalyst;$(NetCoreAppCurrent)-osx</TargetFrameworks> | ||
<TestRuntime>true</TestRuntime> | ||
<HybridGlobalization>true</HybridGlobalization> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="HybridMode.cs" /> | ||
</ItemGroup> | ||
</Project> |
48 changes: 48 additions & 0 deletions
48
src/libraries/System.Globalization/tests/Hybrid/HybridMode.cs
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,48 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Collections.Generic; | ||
using Xunit; | ||
|
||
namespace System.Globalization.Tests | ||
{ | ||
public class HybridModeTests | ||
{ | ||
public static IEnumerable<object[]> EnglishName_TestData() | ||
{ | ||
yield return new object[] { "en-US", "English (United States)" }; | ||
yield return new object[] { "fr-FR", "French (France)" }; | ||
} | ||
|
||
public static IEnumerable<object[]> NativeName_TestData() | ||
{ | ||
yield return new object[] { "en-US", "English (United States)" }; | ||
yield return new object[] { "fr-FR", "français (France)" }; | ||
yield return new object[] { "en-CA", "English (Canada)" }; | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(EnglishName_TestData))] | ||
public void TestEnglishName(string cultureName, string expected) | ||
{ | ||
CultureInfo myTestCulture = new CultureInfo(cultureName); | ||
Assert.Equal(expected, myTestCulture.EnglishName); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(NativeName_TestData))] | ||
public void TestNativeName(string cultureName, string expected) | ||
{ | ||
CultureInfo myTestCulture = new CultureInfo(cultureName); | ||
Assert.Equal(expected, myTestCulture.NativeName); | ||
} | ||
|
||
[Theory] | ||
[InlineData("de-DE", "de")] | ||
[InlineData("en-US", "en")] | ||
public void TwoLetterISOLanguageName(string name, string expected) | ||
{ | ||
Assert.Equal(expected, new CultureInfo(name).TwoLetterISOLanguageName); | ||
} | ||
} | ||
} |
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
46 changes: 46 additions & 0 deletions
46
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.OSX.cs
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,46 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Diagnostics; | ||
|
||
namespace System.Globalization | ||
{ | ||
internal sealed partial class CultureData | ||
{ | ||
/// <summary> | ||
/// This method uses the sRealName field (which is initialized by the constructor before this is called) to | ||
/// initialize the rest of the state of CultureData based on the underlying OS globalization library. | ||
/// </summary> | ||
private bool InitNativeCultureDataCore() | ||
{ | ||
Debug.Assert(_sRealName != null); | ||
Debug.Assert(!GlobalizationMode.Invariant); | ||
string realNameBuffer = _sRealName; | ||
|
||
_sWindowsName = GetLocaleNameNative(realNameBuffer); | ||
return true; | ||
} | ||
|
||
internal static unsafe string GetLocaleNameNative(string localeName) | ||
{ | ||
return Interop.Globalization.GetLocaleNameNative(localeName); | ||
} | ||
|
||
private string GetLocaleInfoNative(LocaleStringData type) | ||
{ | ||
Debug.Assert(!GlobalizationMode.Invariant); | ||
Debug.Assert(_sWindowsName != null, "[CultureData.GetLocaleInfoNative] Expected _sWindowsName to be populated already"); | ||
|
||
return GetLocaleInfoNative(_sWindowsName, type); | ||
} | ||
|
||
// 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 unsafe string GetLocaleInfoNative(string localeName, LocaleStringData type) | ||
{ | ||
Debug.Assert(localeName != null, "[CultureData.GetLocaleInfoNative] Expected localeName to be not be null"); | ||
|
||
return Interop.Globalization.GetLocaleInfoStringNative(localeName, (uint)type); | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.
f561a05
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.
#84233