0

I want to change showing date time format from English to Farsi in backed Umbraco. I apply this setting in web.config.But did not work. (date picker(publish at & Remove at) in properties tab)

<globalization enableClientBasedCulture="true" requestEncoding="UTF-8" responseEncoding="UTF-8" uiCulture="fa" culture="fa"/>

How can I do it?

x19
  • 8,277
  • 15
  • 68
  • 126

3 Answers3

2

The date format did not change based on used language for me.

I see date format hard-coded in umbraco_client\DateTimePicker\umbDateTimePicker.js Change as desired then update client dependency:

  1. App_Data\Temp\ClientDependency - either dump the CDJs or lookup which exact one is being used for umbDateTimePicker.js in the appropriate XML file for your server "{ServerName}-{IDString}-map.xml" and then remove the CDJ file that is the compiled js including umbDateTimePicker.js
  2. Restart app / appPool to trigger the generation of the new ClientDependency file with your new settings.

I'm also seeing hard-coded date time format strings in umbraco.controls: umbraco.uicontrols.DatePicker.DateTimePicker.DateTime setter.

Done on Various Umbraco 4.x versions.

jeffreypriebe
  • 2,267
  • 25
  • 30
1

Language in the Umbraco backend is determined by the user logged in. As of right now, Umbraco only supports the following languages out of the box:

  • Danish
  • German
  • English (UK)
  • English (US)
  • Spanish
  • French
  • Hebrew (Israel)
  • Italian
  • Japanese
  • Korean
  • Dutch
  • Norwegian
  • Polish
  • Portuguese Brazil
  • Russian
  • Swedish
  • Chinese (Simple)

Depending on which language is selected for that specific user, the date will display in the format appropriate to that culture.

This forum post, Farsi and rtl support...., gives some information on how to add a new translation, if that interests you at all.

Douglas Ludlow
  • 10,754
  • 6
  • 30
  • 54
0

As i search, unfortunately umbraco does not support Persian date time forma but you can study FormatDateTime and change the appearance to format like yyyy/mm/dd but for full name of months like فروردین اردیبهشت you should create your own control or use other staff like PersianDate® (PD) In case of code to develop a custom control you can study PersianCalendar Class and this tiny solution :^)

if your date is a Gregorian date then First you must convert it to Jalali date like this:

    PersianCalendar jc = new PersianCalendar();
    DateTime date = new DateTime(jc.GetYear(d), jc.GetMonth(d), jc.GetDayOfMonth(d));
    string print = string.Format("{0:0000}/{1:00}/{2:00}", date.Year, date.Month, date.Day);

but if your date is a Jalali date already then just use:

    string print = string.Format("{0:0000}/{1:00}/{2:00}", date.Year, date.Month, date.Day);

now if you have a string contains a Jalali date like "1390/12/10" and you want to get its day name it ll be a bit tricky.

    public static string GetDayOfWeekName(this DateTime date)
    {
        PersianCalendar jc = new PersianCalendar();
        DateTime d = jc.ToDateTime(date.Year, date.Month, date.Day, 0, 0, 0, 0, PersianCalendar.PersianEra);

        switch (d.DayOfWeek)
        {
            case DayOfWeek.Saturday: return "شنبه";
            case DayOfWeek.Sunday: return "يکشنبه";
            case DayOfWeek.Monday: return "دوشنبه";
            case DayOfWeek.Tuesday: return "سه‏ شنبه";
            case DayOfWeek.Wednesday: return "چهارشنبه";
            case DayOfWeek.Thursday: return "پنجشنبه";
            case DayOfWeek.Friday: return "جمعه";
            default: return "";
        }

First you Should convert it to Gregorian Date then get the Day Name. but not for Months name:

    public static string GetMonthName(this DateTime date)
    {
        switch (date.Month)
        {
            case 1: return "فررودين";
            case 2: return "ارديبهشت";
            case 3: return "خرداد";
            case 4: return "تير‏";
            case 5: return "مرداد";
            case 6: return "شهريور";
            case 7: return "مهر";
            case 8: return "آبان";
            case 9: return "آذر";
            case 10: return "دي";
            case 11: return "بهمن";
            case 12: return "اسفند";
            default: return "";
        }
    }

i would be appreciated if i could provide you more useful post and please let me know it!

saeed
  • 2,477
  • 2
  • 23
  • 40