dotnet / AspNetCore.Docs

Documentation for ASP.NET Core
https://docs.microsoft.com/aspnet/core
Creative Commons Attribution 4.0 International
12.66k stars 25.28k forks source link

Any simpler solutions to the globalisation issue? #6834

Closed jurva closed 5 years ago

jurva commented 6 years ago

I am a bit disappointed of the way the issue of decimal point is handled, both in the SDK and the tutorial. It is a real show stopper, not just a minor cosmetic issue. Or am I missing something? The discussions in the link to the Github issue #4076 are unnecessarily difficult to follow. What does this mean: "Unfortunately those are for bower and the ASP.NET CORE team moved away (a good thing) from bower so if you want to use the recommended NPM way, you can still do it. Either way, I highly recommend you check out both projects for documentation and more info."? "you can still do it"? "check out projects...?" Not anymore used by Core team? Oh, really?

Does it mean that MS has left the support for something as crucial as input validation of other than US locales to third party libraries which need to be found self from forums, then downloaded, read and understood obscure instructions to install, take into use etc. etc. by most of the Visual Studio and ASP.Net Core users just to make their first web pages to run in an acceptable way? Is this the ONLY way of making this simple thing work somehow? Why didn't I run into this type of issues when I worked in the old-fashined ASP.Net pages? I find it very difficult to believe that such a basic thing is not handled so that it would be static part of the development platform or at least something like an option in the Visual Studio (if it needs to be)? Instead, everybody outside US has to wrestle with it.

Could we just bypass javascript validation at client side and do validation at the server side using some other, more traditional and easier-to-implement techniques (e.g., C# code)?


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

jurva commented 6 years ago

Perhaps we could use a string parameter, add a suitable regex, which handles both decimal separators (which would suit me as well) and then convert to int for the database inserts and updates? Or a duplicate, as a string, which is not in the database but which is automatically copied to the int parameter for the database ops? Something along those lines.

jurva commented 6 years ago

One more thing. I did not find all the necessary *.js files from the downloaded globalize-1.3.0.zip package described in the instructions, after it says: "_ValidationScriptsPartial.cshtml add the new required javascript files (after jQuery)". For example, jquery.validate.globalize.js was missing.

Furthermore, two files had duplicates in different subdirectories. With almost no experience of jQuery, I don't know how to move forward.

jurva commented 6 years ago

And yet another, positive follow-up. Using the steps here, I was finally able to at least enter prices, using format "7.99": https://joonasw.net/view/aspnet-core-localization-deep-dive (this guy seems to be my fellow countryman). Anyway, due to my almost total lack of experience and knowledge of the localization features, I don't know how "correctly" the solution works but if I add a query parameter culture=fi-FI, it shows the movie list using comma as a decimal point. However, when I edit a movie entry, I still have to use a dot as a decimal separator. This time it accepts it, though. Just one note for those who might be interested of the solution (or develop it further): I had to save the resource file as "Resources/Controllers/HomeController.fi-FI.resx", which he mentions as an alternative. The version where the name of the resource file contained the name "HomeController" did not work. Don't know why.

Rick-Anderson commented 6 years ago

@jurva where does https://joonasw.net/view/aspnet-core-localization-deep-dive show how to handle decimal? Was https://www.codeproject.com/Articles/1212247/jQuery-culture-validation-in-ASP-NET-Core helpful?

Rick-Anderson commented 6 years ago

@jurva I updated the instructions in #4076 - does that help?

jurva commented 6 years ago

Well, it doesn't focus on the decimal issue but as a side effect, it partly solved my primary problem, which was that NEITHER period NOR comma was accepted as a decimal point.

Comma, which is officially used in Finland and many other European countries as a decimal separator (which, IMHO, is quite unfortunate), was rejected at the client end after tabbing to the next field (error = "The field Price must be a number.") while a period was not rejected until I clicked the Save button, which, I believe means it is rejected at the server-side (error = "The value '7.98' is not valid for Price.").

I believe the problem was partly solved (i.e., accepting a period as a decimal point) by adding these lines to Startup.cs, as suggested by Joonas, above the "app.UseMvc(routes =>" line. I haven't tested yet but I don't think the part of code shown by Joonas – including the string resource file – where he logs a localized text line to the debugger output, was needed to fix the problem. However, it is nice to know at least one way how to support multiple languages.

IList supportedCultures = new List { new CultureInfo("en-US"), new CultureInfo("fi-FI"), }; app.UseRequestLocalization(new RequestLocalizationOptions { DefaultRequestCulture = new RequestCulture("en-US"), SupportedCultures = supportedCultures, SupportedUICultures = supportedCultures });

I wrote above and before that the aforementioned fix "partly solves" the problem. That's because, at least in Finland, many people commonly use the period as the decimal point separator when they write text. So, if they know the problem, they can work around it. Likewise, ":" is often used as an hours:minutes:seconds separator, although the formal version requires a period (e.g., 18:30 vs. 18.30 vs 6 pm). Most likely this habit is a result of so much input coming from English-speaking countries, in the computer business and among young people in particular.

It will be easy for me, at least in some cases (e.g., in a new in-house system, which I am developing at the moment), to instruct people to use a period instead of a comma.

jurva commented 6 years ago

Oops! I forgot to mention that these lines were also needed in ConfigureServices():

services.AddLocalization(o => { // We will put our translations in a folder called Resources o.ResourcesPath = "Resources"; });

Without them, I get an exception. Don't know why.

hishamco commented 6 years ago

@jurva seems I'm late, but can I know what's the progress on this? what is the real show stopper that you mentioned in the first thread?

jurva commented 6 years ago

I decided to force using decimal dot and format yyyy-mm-dd everywhere. It was just too much trouble to try to support user-specific regions everywhere and in every browser. My project was targeting IT professionals, to whom it is not an issue to use US formats for dates and decimal numbers.

hishamco commented 6 years ago

As I understand you want to use decimal dot and yyyy-mm-dd format regardless of what's the current culture, Am I right?

jurva commented 6 years ago

No, I didn't specifically WANT to, but I HAD to. It just was the easiest and fastest way of solving the issue at hand because I couldn't get it understand the date format nor the decimal comma, which, unfortunately, is the standard decimal separator in Finnish/Finland – and in many other European countries as well. Either the client-end validation or the server-end validation rejected the dot or the comma. It would have required installing all sorts of script libraries from the Internet and my initial attemps failed. My humble opinion is that the current implementation/configuration/setup of this issue in general in Visual Studio or Core 2 or libraries or templates or whatever is not optimal for international developers and end users. It shouldn't be that difficult. During my 30+ years in software development, I have seen it so many times before that a support non-US character sets or languages has been an afterthought. Remember all the hassle with national character sets in ASCII? Having said that, I and many people here, at least in IT business, do use English versions of Windows (and Visual Studio and other software, too) with Finnish keyboard and regional settings.

hishamco commented 6 years ago

I see, I thought you want to know how to enforce the decimal dot and date format in new localization APIs, because the current APIs let you did that, but i'm not sure about the jquery validation

hishamco commented 6 years ago

@Rick-Anderson what's the action need here?

Rick-Anderson commented 5 years ago

Thanks for contacting us. We don’t have the resources to invest in this area, so we are closing the issue. Should your request generate enough 👍 responses, we’ll reconsider.