-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
CultureInfo should not depend on local computer settings #11228
Comments
I'm not sure, to be honest. If the DateTime format is changed intentionally then it is because you want to use that specific DateTime format. Then it would defeat the purpose of having it changed. Generally, if you have an application that requires this DateTime format to be changed then an option is to isolate it inside a Docker container and to not use Orchard Core in the same container. If these 2 environments have incompatibility then make them use a different one ... Personally, I prefer leaving the option to change the DateTime format intentionally, than to restrict it. |
There can be many reasons to change the system date format that have nothing to do with the website. I agree that using a container is a valid workaround, but it feels like an overkill if it's otherwise not needed. |
That would make more sense. |
I don't think it's good idea to change the date time settings for a server because may it affects the clients Second if you this change need to be applied it could be in cultures confugration, no need to new up an instance of |
Enabling Location feature should solve this if you doesn’t want to enable localization feature then set UI culture in program.cs related issues |
The server perhaps shouldn't customize the date format but the app should never rely on the server's configuration (apart from the basic runtime requirements) either. So just as we don't rely on the server's locale, we shouldn't on the date format either. Also, this is not just an issues in production but in local development too. The point is, that if you want to have consistent date displays, you need to do what Dávid has demonstrated. |
@Piedone @DAud-IcI OC the functionality works as desired and depends on how ASP.NET reads culture data from OS.
In above scenario - IMO you are really changing |
@ns8482e As I've said in my previous comment Localization is already enabled. This issue is about how Localization behaves when it automatically sets
I doubt it. The browser only sends the culture code ( |
To make it clear, ASP.NET Localization middleware already sets the cultures the same way that we did without setting |
Correct I meant the same as per my comment below
The culture locale sent by your browser - you customized the short date format for that locale so ASP.NET renders what you asked to do. |
Which part of |
If you add support for another culture (e.g. fr ) in OC - and change your browser's locale priority (to fr) to new culture it will change the date format for that culture. |
The problem is not the culture. The problem is a date format within the specified culture. It's all en-US but depending on the server's settings, the same en-US culture can use different date formats with the same format string. |
He changed the short date format for the |
That we know. The point of this issue is being able to configure the date time format used by Orchard for a given culture to be reliably exactly the same everywhere, regardless of server settings. The culture settings of the server shouldn't matter. |
@Piedone What happens if you want to change the DateTime format intentionally then? The reason why we kept it like this is that this is how it is handled by the ASP.NET Localization middleware. Here, what is suggested is to hack the behavior of the middleware. While I see that this could lead to an issue changing the DateTime of the En-Us culture, for example, this is not supposed to affect database transactions, this should only affect DateTime display, which is the goal here. I can't agree on the proposed change and I believe that I already had this discussion with @sebastienros and @jtkech a while ago. As far as environment variables go, I think that if they are not the same from one environment to another then that's a configuration of the environment issue to me. |
@DAud-IcI try to reproduce the issue in a simple ASP.NET Core application, if you get the same result, you can file an issue in ASP.NET Core repo, otherwise it might related to |
I don't see why we'd hack the ASP.NET Localization middleware. This is about changing the behavior of Culture settings are already an environment variable. To make the app not depend on those, we have culture settings in Orchard (and similarly we have time zone settings). We don't say that these should also be provided by the environment but rather we override them with Orchard settings. Here, we're talking about a subset of culture settings. Why would that be any different? |
IMHO changing regional settings and that gets reflected on ASP.NET applications is a feature and expected behavior. If you don't want that change then why do you even change default settings on server at first place? If you have specific requirement to have all other asp.net app (any other apps) read regional settings but not specific orchard core app then it's custom use-case You can achieve it by modifying |
@Piedone And this CultureScope uses the same mechanic as the Localization Middleware to be consistent. |
👀 |
@ns8482e I don't want to change this on the server. In fact, this is something out of my control (while Dávid mentioned our CI server, the problem is not its configuration but rather that it, the developers' machines, and the production server may all be different, and they are), and the problem is that it's not consistent in all environments. Hence, Dávid and I am presenting the point of making the app not depend on this particular configuration of the server, just as it does not depend on any other configuration of the server either. Putting aside for a moment what the Localization Middleware does and why, and whether we should do the same: Which one of these do you agree with and why?
For now, forget about implementation details, or whether it should be part of Orchard, or anything else. I just want to understand whether we have some common ground and thus whether talking about specifics makes sense. 👀 |
I may refer to this issue: #5595 Related to that, there is also the fact that each OS has its own culture code listing. There have always been discrepancies between different OS and that's one of the reasons why the DateTime format has always been modifiable under Windows. Unless all OS would be using the same standardized cultures it's always going to be a challenge to be able to make a UI to be consistent from one OS to another. This is mainly why I'm saying that the issue lies deeper and that this should be handled by making sure that you compare apples with apples when you are trying to verify if the UI is displayed correctly. Of course, changing a DateTime format on a system will cause the UI to be different because you are not comparing it with the same OS environment variables. And, for that matter, running CI tests for example need to be compared with a host system that is equivalent to the CI itself. So, for that matter, there is always Docker. Also, I believe that on Windows, having the ability to change the different string formats has been made to be able to fix issues caused by these discrepancies. So, removing the ability to change these formats will also cause issues for others. |
What issues do you mean? Just to clarify, I'm not against changing this format. I'm for being able to change it in Orchard. While having consistency across different OS families is indeed an issue, and something I agree that ultimately .NET needs to solve, that's out of scope here. This particular issue with the short date format is a Windows-only one, and the parameter Dávid mentioned only has an effect on Windows. We're only talking about differences of date settings between different Windows installations. |
I have thought about it too. And to drive a parallel with Timezones management, installing OC on a system should not behave differently based on the system's settings, as much as it can. To fix this problem I believe we should be able to at least create a standardized culture based on the identifier, that is not changed by local settings. And optionally provide a way to change these settings for any culture, probably from configuration only. Has anyone found a related issue in ASP.NET? This ought to be the same there with request culture providers. |
If I'm not I saw an issue related a date format long time ago, hope to find it |
Didn't say to use it if this is what you meant ;) Just showed the aspnet code that doesn't use |
I just meant that it is risky to change the behavior of the ASP.NET Middleware. This could work but that seems hacky unless it is supported on every level which it doesn't seem to be at first sight. And we both know that doing this leads to a lot of needing hacks everywhere which I don't really like to encourage. I'm not going to approve the pull request for that matter. But, else, let's find a compromise if people need this. To me, it's simpler to not override the Culture settings on a server. And if it is because of a particular developer PC culture setting then it is a really specific use case that we can see that the ASP.NET team did not take care of. So, should we? The proper resolution would be to open up an issue on the ASP.NET localization middleware repository but that can take a while to resolve in that case. |
@jtkech that's what i meant here
If we open I'm sure it may take long time probably years ;) coz all of the team that working on localizations are not active in the repo, probably because the feature is stable or they moved into another ASP.NET Core components |
Based on the fact that aspnet uses overrides we need to keep the current behavior. |
So, let use keep the current behavior, but someone can tamper the localization middleware to make this happen. @Piedone can we implement this in Lombiq or OCC if there's no plan to implement it here? |
Where exactly is ASP.NET using overrides consciously? |
That looks more like a default behavior when you're specifying cultures only by their names. Otherwise, this is not enforced and you can add |
Yes, see #11228 (comment)
And then the winning culture is set here https://github.com/dotnet/aspnetcore/blob/b2679bf0bfe96cd3f8e1663868f5c87a1b0dbadd/src/Middleware/Localization/src/RequestLocalizationMiddleware.cs#L129-L133 Hmm, one solution would be to not use updated: Maybe a configurable option for the useUserOverride value to use. |
While rewriting the extension methods might fix the issue do we really want to do that in Orchard Core? We tried to avoid doing such things when we wrote the actual Localization middleware module because we were doing too much fiddling here and there while we should rely on the ASP.NET Middleware. That would add a lot of code for a unique use case that can be fixed by not changing the actual culture settings in Windows. |
@jtkech, yes, this would be an optional configuration. @Skrypt as I elaborated under #11228 (comment), environment settings is not something possible to enforce if we go beyond the very trivial use-case. |
@jtkech I tried simialr approach when I planned to start this PR, but how you can avoid setting the cultures using |
He should not use So here we would not change the middleware, only the way we set options, and the culture scope as suggested at the beginning of this issue, but as said by @Skrypt not sure we want to override the default behavior, I don't know so I let others decide ;) |
Nothing, prevent him from doing that, moreover everyone TRUST localization middleware and know how everything handled
Right Again, I see the solution may solve the issue partially, but change the default behavior of the middleware, we may ask @sebastienros to talk with Damian Edwards about this issue to handle it in Localization middleware if it's the right behavior, as @jtkech said let others decide ;) |
@hishamco Okay cool then Only a little precision about my own comment
I meant he should not update it directly (just let the middleware do it), unless he knows what he does as you do with your CultureScope. Also, yes the behavior would change but not the behavior of the middleware itself, only the way we set the options by not using their helpers (that don't use useUserOverride). |
I can already hear the aspnet devs saying that it would be an issue that Culture settings are not reflecting the system's configuration. Similar to ICU libraries in dotnet... Hence I would agree about a lower level application wide setting that could change the current default behavior or CultureInfo. So this can be global. |
@jtkech I'm planning to submit a PR for this, did you see adding a middleware that sets Please let me if it's fine to discuss here or via Gitter |
Hmm, as I remember I was not suggesting to update/add any middleware but eventually use an |
Ya I remember ;) also we can have "useUserOverride" configurable |
@DAud-IcI do you mean restarting the PC/Laptop or IIS? |
I meant the Orchard Core web application, e.g. |
I just started a PR, hope it's ready tonight or tomorrow |
My suggestion was to have a single bool in the app settings like |
Describe the bug
When the library sets the culture using
new CultureInfo(culture)
you can get unexpected results if this is also the system's culture and data formats were customized. This could be a problem if the server wants one data format for internal administrative use that's different from the culture's canonical format.For example you have an en-US server with date format set to ISO 8601 (this is actually what we have on our CI - this problem is most painful while doing UI tests). Then if you want to display a date in OC with the site set to American locale, it will display it using ISO 8601 which is not what you'd expect. The site's internationalization should not depend on the local format settings.
To Reproduce
This repro assumes you have Windows 10 with en-US region settings:
![image](https://user-images.githubusercontent.com/4007293/154873250-17ea22f4-0815-4980-9ff9-2be42a1f20eb.png)
Steps to reproduce the behavior on Windows:
@T["Date: {0:d}", new DateTime(2022, 02, 21, 12, 0)]
Date: 2/21/2022
.Date: 2022-02-21
.Expected behavior
You should still see
Date: 2/21/2022
.Speculation
I believe the problem can be solved simply by altering
OrchardCore.Localization.CultureScope.SetCultures
to generate fresh stock cultures. So from this:Into this:
The text was updated successfully, but these errors were encountered: