How to change date format for Admin interface?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
10 лет назад
The issue is not Telerik related.
Telerik supports gllobalization (although the NL_nl culture is incorrect in the Telerik localization)

If you enable Telerik globalization as described in this topic you will run into issues with the Jquery validation (both numeric and datetime).

Using jquery.globalize will solve the issues on the numeric format.

The DateTime validation issues require more work as nopCommerce uses two dateTime formats (one with time and ont without)
This requires overriding the default date validation functions in jquery.validate.

Besides that it will need to be tested properly to make sure there are no other issues.

If you really need this fixed fast, why not fix it yourself and contribute the code changes back to nopCommerce.

I need the issue fixed as well and, if I get the time, might even do it myself in the next few months.

Regards,
Dennis
10 лет назад
Мне удалось разродиться катарсисом: Валидация даты в формате ru-Ru работает как нужно.
Что я сделал:
1. Подключенные скрипты:
Html.AppendScriptParts("~/Administration/Scripts/Localization/globalize.culture.ru.js");
Html.AppendScriptParts("~/Administration/Scripts/Localization/globalize.js");
Html.AppendScriptParts("~/Administration/Scripts/jquery.validate.unobtrusive.min.js");
Html.AppendScriptParts("~/Administration/Scripts/jquery.validate.min.js");
Html.AppendScriptParts("~/Administration/Scripts/jquery-1.8.1.min.js");

2. Переопределение проверки
<script>
        $(document).ready(function () {
            var currentCulture = $("meta[name='accept-language']").prop("content");

            // Set Globalize to the current culture driven by the meta tag (if any)
            if (currentCulture) {
                Globalize.culture(currentCulture);
            }

            //Tell the validator that we want numbers parsed using Globalize.js
            $.validator.methods.number = function (value, element) {
                if (Globalize.parseFloat(value)) {
                    return true;
                }
                return false;
            }

            //Tell the validator that we want dates parsed using Globalize.js
            $.validator.methods.date = function (value, element) {
                if (Globalize.parseDate(value)) {
                    return true;
                }
                return false;
            }

            //Fix the range to use globalized methods
            jQuery.extend(jQuery.validator.methods, {
                range: function (value, element, param) {
                    //Use the Globalization plugin to parse the value
                    var val = Globalize.parseFloat(value);
                    return this.optional(element) || (val >= param[0] && val <= param[1]);
                }
            });
        });
    </script>

3. В Хед добавляем (не важно как: руками или динамически):
<meta name="accept-language" content="ru-RU" />

4. Добавляем шаблон в globalize.culture.ru.js:

patterns: {
                    d: "dd.MM.yyyy",
                    D: "d MMMM yyyy 'г.'",
                    t: "H:mm",
                    T: "H:mm:ss",
                    f: "d MMMM yyyy 'г.' H:mm",
                    F: "d MMMM yyyy 'г.' H:mm:ss",
                    Y: "MMMM yyyy",
                   J: "dd.MM.yyyy H:mm"
                }

Это реально помогло решить проблему.
10 лет назад
Hello All,

Just wondered if anyone has manage to fix this en-US issue on the admin section?

I am using Nop3.1 and help and advice will be appreciated.
Thanks.
10 лет назад
To localize the backoffice fully (I tested decimal numbers & dates) use the following Post:

•  https://www.nopcommerce.com/boards/t/19235/latest-telerik-version-incorrectly-shows-decimals-in-different-locales.aspx?p=2#78878

After following the above steps it should work fine in Internet Explorer and other browsers.

There is a problem with Chrome regarding the jQuery date field validations. This can be corrected following this post:

•  http://www.codeproject.com/Tips/579279/Fixing-jQuery-non-US-Date-Validation-for-Chrome

After performing the changes in the two links above, the admin interface works correctly for any culture.
10 лет назад
I have added a diff file to https://nopcommerce.codeplex.com/workitem/10321 in hope that it will help others and maybe with enough testing with different cultures can be integrated into the main trunk. I have only done limited testing with IE and en-gb and it seems to work fine however if the contributors think I have done something wrong please tell me and I will update the diff...

Regards,

Robin.
10 лет назад
We already have an official solution for this problem?
10 лет назад
devdecision wrote:
We already have an official solution for this problem?


Hi, Could you please share that official solution? We are using 3.1 in the UK and using the admin in the US date format is not ideal.
10 лет назад
Sorry, it was a grammar error.

I would like to know, if someone find a solution for this problem?
10 лет назад
devdecision wrote:
Sorry, it was a grammar error.

I would like to know, if someone find a solution for this problem?


I don't think there is an official solution to this issue but I have also managed to fix the US date issue on my UK site by following bubbi's post on page 3. But somehow it worked for me without following all the steps or not following the steps exactly as they were.

I am very new to MVC and cannot figure out why and how it worked without following all the steps as they are but here is what I did;

Step 1 - at the bottom of  _AdminLayout.cshtml page;

change
    @(Html.Telerik().ScriptRegistrar()
            .jQuery(false)
            .jQueryValidation(false)
            )
to
    @(Html.Telerik().ScriptRegistrar()
            .jQuery(false)
            .jQueryValidation(false)
            .Globalization(true)
            )

NOTE: My issue was about the date not the decimal sign so I have ignored the step 2 on bubie's post

Step 2 - changes on global.asax file;
As I am using version 3.1, there is only one line of code on my "global.asax" so I had to go to source file (Global.asax.cs) file and make the following change, again towards the bottom of the page/code

change
      var culture = new CultureInfo("en-US");
to
      var culture = new CultureInfo("en-GB");

Just these two steps was good enough to display the dates in dd/mm/yyy format on IE and I had no issues with the decimal prices . However on Google chrome I also experienced an issue with the date picker so I applied the fix on the following page;
http://www.codeproject.com/Tips/579279/Fixing-jQuery-non-US-Date-Validation-for-Chrome

Step 3 - add the script to _AdminLayout.cshtml head tag

I have simply added the following code just before my </head> tag;

<script>
// fix date validation for chrome
    jQuery.extend(jQuery.validator.methods, {
      date: function (value, element) {
        var isChrome = window.chrome;
        // make correction for chrome
        if (isChrome) {
          var d = new Date();
          return this.optional(element) ||
          !/Invalid|NaN/.test(new Date(d.toLocaleDateString(value)));
        }
        // leave default behavior
        else {
          return this.optional(element) ||
          !/Invalid|NaN/.test(new Date(value));
        }
      }
    });
</script>

And that is it. It all worked for me. I am not sure if I ended up breaking something else but a few tests and page views with changes to prices, dates, kg, mm and similar all proved to working so far.
10 лет назад
If you look at my post above you will notice I have attached a diff file to the work item on codeplex. You can use this to implement the solution quickly.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.