-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
macOS / Mac Catalyst / iOS: CurrentThread.Current[UI]Culture is always the invariant culture #68321
Comments
Tagging subscribers to this area: @dotnet/area-system-globalization Issue DetailsDescription
This affects both Mono (on Mac Catalyst) and CoreCLR (no macOS). Ref: dotnet/macios#14740 Reproduction Steps
dotnet new maccatalyst
using System.Globalization;
Console.WriteLine ($"CurrentUICulture: {GetString (Thread.CurrentThread.CurrentUICulture)}");
Console.WriteLine ($"CurrentCulture: {GetString (Thread.CurrentThread.CurrentCulture)}");
Thread.CurrentThread.CurrentUICulture = new CultureInfo ("en-US");
Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
Console.WriteLine ("After setting to 'en-US':");
Console.WriteLine ($"CurrentUICulture: {GetString (Thread.CurrentThread.CurrentUICulture)}");
Console.WriteLine ($"CurrentCulture: {GetString (Thread.CurrentThread.CurrentCulture)}");
static string GetString (CultureInfo ci)
{
return $"Name: {ci.Name} NativeName: '{ci.NativeName}' DisplayName: '{ci.DisplayName}' EnglishName: '{ci.EnglishName}'";
}
dotnet run
$ ./bin/Debug/net6.0-maccatalyst/maccatalyst-x64/currentculturetest.app/Contents/MacOS/currentculturetest
[...]
CurrentUICulture: Name: NativeName: 'Invariant Language (Invariant Country)' DisplayName: 'Invariant Language (Invariant Country)' EnglishName: 'Invariant Language (Invariant Country)'
CurrentCulture: Name: NativeName: 'Invariant Language (Invariant Country)' DisplayName: 'Invariant Language (Invariant Country)' EnglishName: 'Invariant Language (Invariant Country)'
After setting to 'en-US':
CurrentUICulture: Name: en-US NativeName: 'en (US)' DisplayName: 'en (US)' EnglishName: 'en (US)'
CurrentCulture: Name: en-US NativeName: 'en (US)' DisplayName: 'en (US)' EnglishName: 'en (US) Complete test project: currentculturetest-d0b7a3f.zip Expected behaviorCurrentThread.Current[UI]Culture should reflect whatever's configured in the OS. Actual behaviorAlways Invariant culture Regression?Don't know Known WorkaroundsNo response ConfigurationNo response Other informationNo response
|
In legacy Xamarin, the current culture was set in the get_darwin_locale method in mono. This function doesn't exist anymore in this repo (removed in 738066c). |
For reference, this is the output of an equivalent Xamarin.Mac test project:
|
Looks like we're relying on the default to come out of ICU, which I believe is "en_US_POSIX" and we subsequently ignore runtime/src/native/libs/System.Globalization.Native/pal_locale.c Lines 138 to 141 in 7414af2
The right way would be to add a get_darwin_locale equivalent. |
ICU uses system default, which you can check with
This applies to all supported Unix OS and versions of .NET Core; it is not specific to Darwin and .NET 6. |
Yes, setting the @steveisok will you take care with this issue? I am seeing you have marked for |
That's really only feasible for command-line executables. There's no user-friendly way to set LANG for normal (UI) apps. |
Agree. The UI apps can force the culture in the startup code too. I am not suggesting that but just mentioning it.
does
|
Tagging subscribers to 'os-tvos': @steveisok, @akoeplinger Issue DetailsDescription
This affects both Mono (on Mac Catalyst) and CoreCLR (no macOS). Ref: dotnet/macios#14740 Reproduction Steps
dotnet new maccatalyst
using System.Globalization;
Console.WriteLine ($"CurrentUICulture: {GetString (Thread.CurrentThread.CurrentUICulture)}");
Console.WriteLine ($"CurrentCulture: {GetString (Thread.CurrentThread.CurrentCulture)}");
Thread.CurrentThread.CurrentUICulture = new CultureInfo ("en-US");
Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
Console.WriteLine ("After setting to 'en-US':");
Console.WriteLine ($"CurrentUICulture: {GetString (Thread.CurrentThread.CurrentUICulture)}");
Console.WriteLine ($"CurrentCulture: {GetString (Thread.CurrentThread.CurrentCulture)}");
static string GetString (CultureInfo ci)
{
return $"Name: {ci.Name} NativeName: '{ci.NativeName}' DisplayName: '{ci.DisplayName}' EnglishName: '{ci.EnglishName}'";
}
dotnet run
$ ./bin/Debug/net6.0-maccatalyst/maccatalyst-x64/currentculturetest.app/Contents/MacOS/currentculturetest
[...]
CurrentUICulture: Name: NativeName: 'Invariant Language (Invariant Country)' DisplayName: 'Invariant Language (Invariant Country)' EnglishName: 'Invariant Language (Invariant Country)'
CurrentCulture: Name: NativeName: 'Invariant Language (Invariant Country)' DisplayName: 'Invariant Language (Invariant Country)' EnglishName: 'Invariant Language (Invariant Country)'
After setting to 'en-US':
CurrentUICulture: Name: en-US NativeName: 'en (US)' DisplayName: 'en (US)' EnglishName: 'en (US)'
CurrentCulture: Name: en-US NativeName: 'en (US)' DisplayName: 'en (US)' EnglishName: 'en (US) Complete test project: currentculturetest-d0b7a3f.zip Expected behaviorCurrentThread.Current[UI]Culture should reflect whatever's configured in the OS. Actual behaviorAlways Invariant culture Regression?Don't know Known WorkaroundsNo response ConfigurationNo response Other informationNo response
|
Running % locale
LANG=""
LC_COLLATE="C"
LC_CTYPE="UTF-8"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL= This is the same case with some Linux distros, especially in minimal installation mode (or containers). IMO, we should take those cases into account if we are planning to do something about it (not only Darwin). |
What are you suggesting doing here? How you will fix this on Linux? |
I think in addition to porting |
@am11 we are currently calling ICU |
@steveisok I looked into setting LANG in the native main method as a workaround, and I ran into a few issues: It doesn't work with CoreCLR (i.e. on macOS), because CoreCLR links with the system libicucore.dylib, and that library reads LANG in a dylib initializer (so before the native
It seems to work when using Mono as the runtime (iOS, tvOS, Mac Catalyst), until an unknown value for LANG is set (say This leads me to believe that setting LANG isn't viable as a workaround, it's much better to have an easily understandable bug that app developers can work around themselves instead. |
@rolfbjarne the crash because you are using a locale name |
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 dotnet#68321
Tagging subscribers to 'os-ios': @steveisok, @akoeplinger Issue DetailsDescription
This affects both Mono (on Mac Catalyst) and CoreCLR (no macOS). Ref: dotnet/macios#14740 Reproduction Steps
dotnet new maccatalyst
using System.Globalization;
Console.WriteLine ($"CurrentUICulture: {GetString (Thread.CurrentThread.CurrentUICulture)}");
Console.WriteLine ($"CurrentCulture: {GetString (Thread.CurrentThread.CurrentCulture)}");
Thread.CurrentThread.CurrentUICulture = new CultureInfo ("en-US");
Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
Console.WriteLine ("After setting to 'en-US':");
Console.WriteLine ($"CurrentUICulture: {GetString (Thread.CurrentThread.CurrentUICulture)}");
Console.WriteLine ($"CurrentCulture: {GetString (Thread.CurrentThread.CurrentCulture)}");
static string GetString (CultureInfo ci)
{
return $"Name: {ci.Name} NativeName: '{ci.NativeName}' DisplayName: '{ci.DisplayName}' EnglishName: '{ci.EnglishName}'";
}
dotnet run
$ ./bin/Debug/net6.0-maccatalyst/maccatalyst-x64/currentculturetest.app/Contents/MacOS/currentculturetest
[...]
CurrentUICulture: Name: NativeName: 'Invariant Language (Invariant Country)' DisplayName: 'Invariant Language (Invariant Country)' EnglishName: 'Invariant Language (Invariant Country)'
CurrentCulture: Name: NativeName: 'Invariant Language (Invariant Country)' DisplayName: 'Invariant Language (Invariant Country)' EnglishName: 'Invariant Language (Invariant Country)'
After setting to 'en-US':
CurrentUICulture: Name: en-US NativeName: 'en (US)' DisplayName: 'en (US)' EnglishName: 'en (US)'
CurrentCulture: Name: en-US NativeName: 'en (US)' DisplayName: 'en (US)' EnglishName: 'en (US) Complete test project: currentculturetest-d0b7a3f.zip Expected behaviorCurrentThread.Current[UI]Culture should reflect whatever's configured in the OS. Actual behaviorAlways Invariant culture Regression?Don't know Known WorkaroundsNo response ConfigurationNo response Other informationNo response
|
) 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
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
…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 <[email protected]>
Description
Thread.CurrentThread.Current[UI]Culture
is always the invariant culture at launch in macOS and Mac Catalyst (and probably iOS and tvOS as well).This affects both Mono (on Mac Catalyst) and CoreCLR (no macOS).
Ref: dotnet/macios#14740
Ref: dotnet/maui#3962
Reproduction Steps
Complete test project: currentculturetest-d0b7a3f.zip
Expected behavior
CurrentThread.Current[UI]Culture should reflect whatever's configured in the OS.
Actual behavior
Always Invariant culture
Regression?
Don't know
Known Workarounds
No response
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: