Skip to content
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

RequestLocalizationMiddleware does not handle CultureInfo.InvariantCulture since version 8 #58843

Open
1 task done
cloudlucky opened this issue Nov 8, 2024 · 1 comment · May be fixed by #58844
Open
1 task done
Labels
area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlesware

Comments

@cloudlucky
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

The RequestLocalizationMiddleware sets the culture to default even if the RequestLocalizationOptions supports CultureInfo.InvariantCulture since version 8.

Example:

builder.Services.Configure<RequestLocalizationOptions>(options => {
    var supportedCultures = new[]
    {
        CultureInfo.InvariantCulture,
        CultureInfo.GetCultureInfo("fr"),
        CultureInfo.GetCultureInfo("en"),
    };

    options.DefaultRequestCulture = new(supportedCultures[1]);
    options.SupportedCultures = supportedCultures;
    options.SupportedUICultures = supportedCultures;

    options.RequestCultureProviders =
    [
        new DefaultRequestCultureProvider()
    ];
});

public class DefaultRequestCultureProvider : IRequestCultureProvider
{
    public Task<ProviderCultureResult?> DetermineProviderCultureResult(HttpContext httpContext)
    {
        var result = new ProviderCultureResult(culture: CultureInfo.InvariantCulture.Name, uiCulture: CultureInfo.CurrentUICulture.Name);

        return Task.FromResult<ProviderCultureResult?>(result);
    }
}

At the end, CultureInfo.CurrentCulture was always the DefaultRequestCulture instead of CultureInfo.InvariantCulture.

Note: this code worked until version 8

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

No response

Anything else?

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label Nov 8, 2024
@adityamandaleeka
Copy link
Member

It seems like not returning InvariantCulture here was an intentional decision: #46637 (comment)

@mitchdenny, what are your thoughts?

@gfoidl gfoidl added area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlesware and removed area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels labels Nov 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlesware
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants