@Html.Kendo().Culture() doesn't seem to work properly

4 posts, 1 answers
  1. Brad
    Brad avatar
    14 posts
    Member since:
    Jun 2016

    Posted 03 Aug 2016 Link to this post

    I'm using kendo Telerik.UI.for.AspNet.Mvc5 version 2016.2.607 in .net 452

    i have my culture type in web.config set as:

    <globalization uiCulture="de" culture="de-DE" />

    if i use the following code to localize my website, it works fine (see 'first.png')

    <script src="@Url.Content("~/Scripts/kendo/2016.2.607/cultures/kendo.culture." + System.Globalization.CultureInfo.CurrentCulture.Name + ".min.js")"></script>
            <script type="text/javascript">
                $(document).ready(function () {
                    kendo.culture("@System.Globalization.CultureInfo.CurrentCulture.Name");
                });
            </script>

    if i remove that code and use @Html.Kendo().Culture() instead, i en-US date values (see 'second.png')

    if i do a view source, the @Html.Kendo().Culture() seems to be working fine, see below.

    <script>kendo.cultures["de-DE"]={name:"de-DE",numberFormat:{pattern:["-n"],decimals:2,",":".",".":",",groupSize:[3],percent:{pattern:["-n %","n %"],decimals:2,",":".",".":",",groupSize:[3],symbol:"%"},currency:{pattern:["-n $","n $"],decimals:2,",":".",".":",",groupSize:[3],symbol:"€"}},calendars:{standard:{days:{names:["Sonntag","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag"],namesAbbr:["So","Mo","Di","Mi","Do","Fr","Sa"],namesShort:["So","Mo","Di","Mi","Do","Fr","Sa"]},months:{names:["Januar","Februar","März","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember"],namesAbbr:["Jan","Feb","Mrz","Apr","Mai","Jun","Jul","Aug","Sep","Okt","Nov","Dez"]},AM:[""],PM:[""],patterns:{d:"dd.MM.yyyy",D:"dddd, d. MMMM yyyy",F:"dddd, d. MMMM yyyy HH:mm:ss",g:"dd.MM.yyyy HH:mm",G:"dd.MM.yyyy HH:mm:ss",m:"d. MMMM",M:"d. MMMM",s:"yyyy'-'MM'-'dd'T'HH':'mm':'ss",t:"HH:mm",T:"HH:mm:ss",u:"yyyy'-'MM'-'dd HH':'mm':'ss'Z'",y:"MMMM yyyy",Y:"MMMM yyyy"},"/":".",":":":",firstDay:1}}};</script>

    what am i missing?

  2. Daniel
    Admin
    Daniel avatar
    2122 posts

    Posted 08 Aug 2016 Link to this post

    Hello Brad,

    Have you included the code to set the current culture?
    <script type="text/javascript">
        $(document).ready(function () {
            kendo.culture("@System.Globalization.CultureInfo.CurrentCulture.Name");
        });
    </script>
    The Kendo.Culture() helper will only output the culture script. It will not set the culture as current.

    Regards,
    Daniel
    Telerik by Progress
     
    Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
     
  3. Brad
    Brad avatar
    14 posts
    Member since:
    Jun 2016

    Posted 08 Aug 2016 in reply to Daniel Link to this post

    Ah, i didn't get that at all from http://docs.telerik.com/kendo-ui/aspnet-mvc/globalization .  Thanks, it works correctly now.  What about validators?  I shouldn't need to do scripts like:

    $.validator.addMethod('date',<br>               function (value, element) {<br>                   return this.optional(element) || kendo.parseDate(value)<br>               });

    anymore, right?  Plus, i also shouldn't need to set the culture of kendo objects either, like:

    @Html.Kendo().DateTimePickerFor(m => m.ProjectEndDate).Culture(System.Globalization.CultureInfo.CurrentCulture.Name)

    ?  I should be able to leave the 'culture' section out of the datetimepicker?  Or is that not how it works?

  4. Answer
    Daniel
    Admin
    Daniel avatar
    2122 posts

    Posted 09 Aug 2016 Link to this post

    Hello again,

    You will still need the code for the jQuery validation. The current kendo culture is used by default only by the kendo validator. I am not sure if I understand why was setting the culture specifically to the DateTimePicker helper needed. It uses the formats from the current .NET culture by default.

    Regards,
    Daniel
    Telerik by Progress
     
    Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
     
Back to Top