Skip to content

Changing the date / time format reflect to the CurrentCulture all the time #44286

@hishamco

Description

@hishamco

Background and Motivation

Changing the culture date/time format reflect to the default culture, there's no way in the current APIs to allow the user doesn't rely on the system settings

Proposed API

+ private readonly bool _useUserOverride;
+
    private RequestCulture _defaultRequestCulture =
        new RequestCulture(CultureInfo.CurrentCulture, CultureInfo.CurrentUICulture);

- public RequestLocalizationOptions()
+ public RequestLocalizationOptions() : this(useUserOverride: true)
{
-    RequestCultureProviders = new List<IRequestCultureProvider>
-    {
-        new QueryStringRequestCultureProvider { Options = this },
-        new CookieRequestCultureProvider { Options = this },
-        new AcceptLanguageHeaderRequestCultureProvider { Options = this }
-    };
}

+ public RequestLocalizationOptions(bool useUserOverride)
+{
+    _useUserOverride = useUserOverride;
+    RequestCultureProviders = new List<IRequestCultureProvider>
+    {
+        new QueryStringRequestCultureProvider { Options = this },
+        new CookieRequestCultureProvider { Options = this },
+        new AcceptLanguageHeaderRequestCultureProvider { Options = this }
+    };

Usage Examples

var options = new RequestLocalizationOptions(useUserOverride: true);

app.UseRequestLocalization(options);

Alternative Designs

Risks

Metadata

Metadata

Assignees

Labels

api-approvedAPI was approved in API review, it can be implementedarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions