Date and time culture in po?

Topics: Administration, Core, Customizing Orchard, General, Installing Orchard, Localization, Troubleshooting
Dec 26, 2011 at 4:38 PM
Edited Dec 26, 2011 at 4:39 PM

Where I set culture of my orchard instance so that I have my specific culture formats every where like currency and datetime? is it in po? web.config?

All I found talking about orchard-cultures are specific for translations only!!!

Coordinator
Dec 26, 2011 at 7:04 PM

No, it's in settings.

Dec 27, 2011 at 7:25 AM
bertrandleroy wrote:

No, it's in settings.

can u explain more please :)

Coordinator
Dec 27, 2011 at 8:28 AM
Edited Dec 27, 2011 at 8:30 AM

Go to settings, add a culture, select it. Done.

http://docs.orchardproject.net/Documentation/Creating-global-ready-applications#Switchingthesitetoanotherculture

Dec 27, 2011 at 8:55 AM
bertrandleroy wrote:

Go to settings, add a culture, select it. Done.

http://docs.orchardproject.net/Documentation/Creating-global-ready-applications#Switchingthesitetoanotherculture

As I wrote before, changing culture in the settings only change language, not currency or datetime formats!

Dec 27, 2011 at 10:55 AM
Edited Dec 27, 2011 at 10:56 AM

You have to switch the website culture AND download & install language .po : datetime format string are stored there.

But you're right that it does not change the website general culture (use of default currency symbol, etc.).

In some places culture format are hardcoded : datetime picker for example is written to only handle english date/time format (which I must admit is a pain for non-english contributors).

Dec 27, 2011 at 11:19 AM
styx31 wrote:

You have to switch the website culture AND download & install language .po : datetime format string are stored there.

But you're right that it does not change the website general culture (use of default currency symbol, etc.).

In some places culture format are hardcoded : datetime picker for example is written to only handle english date/time format (which I must admit is a pain for non-english contributors).

I hope that changing culture in the web.config will change some important culture formats, if not, then God helps all

Mar 4, 2012 at 10:14 PM

If you want to change how the date and time is displayed for any one blog posting or page, then you need to copy-and-edit several files out of the Core directory used by Orchard.

I am a particular fan of the ISO-8601 datetime standard, so I will use that formatting as my example.

What I did was copy the files:

Parts.Common.Metadata.cshtml
Parts.Common.Metadata.Summary.cshtml

from

Core\Common\Views\

into my theme\Views\ folder. I then edited them as follows:

@{var dateTime = Model.ContentPart.PublishedUtc.AddHours(-8);}
<div class="published">@dateTime.ToString("yyyy-MM-dd, HH:mm")</div>

Notice how I subtracted eight hours (adding negative 8 hours) to allow the date to conform to my local timezone. Otherwise they would have shown the publish date in UTC, which would have been quite a bit off in many cases from the Pacific (UTC-8) timezone I work in.

If you want to modify the string itself, you can use many different layouts. The only reason why I used "yyyy-MM-dd, HH:mm" instead of "u" was because I don’t care to display seconds -- having hours and minutes is good enough.

Mar 5, 2012 at 6:26 AM

Thanks dear rekabis, I think Orchard 1.4 fixed the problem by setting the timezone in the site settings.

Mar 16, 2012 at 12:14 PM
Edited Mar 16, 2012 at 12:18 PM

I still think that localization files are missing the format used to display published date.

default Parts.Common.Metadata.cshtml declares this :

<div class="published">@Display.PublishedState(createdDateTimeUtc: Model.ContentPart.CreatedUtc, publisheddateTimeUtc: Model.ContentPart.PublishedUtc)</div>

And PublishedState shape is declared as follows (in Core\Common\Shape.cs) :

return Display.DateTime(DateTimeUtc: createdDateTimeUtc);

And, finally, DateTimeShape.DateTime is :

[Shape]
public IHtmlString DateTime(DateTime DateTimeUtc, LocalizedString CustomFormat) {
    //using a LocalizedString forces the caller to use a localizable format

    if (CustomFormat == null || String.IsNullOrWhiteSpace(CustomFormat.Text)) {
        return DateTime(DateTimeUtc, _dateTimeLocalization.LongDateTimeFormat);
    }

    return new MvcHtmlString(ConvertToDisplayTime(DateTimeUtc).ToString(CustomFormat.Text));
}

The root of the problem is in Core\Shapes\Localization\DateTimeLocalization (used before by _dateTimeLocalization), where the class defines LongDateTimeFormat, but most of the .po files does not contains it :

public LocalizedString LongDateTimeFormat {
    get { return T("MMM d yyyy h:mm tt"); }
}

So, according this, the only thing you need to do is to add the following entries (french version given as sample) in the Core\App_Data\Localization\fr-FR\orchard.core.po :

#: Orchard.Core.Shapes.DateTimeShapes
#| msgid "January, February, March, April, May, June, July, August, September, October, November, December"
msgctxt "Orchard.Core.Shapes.DateTimeShapes"
msgid "January, February, March, April, May, June, July, August, September, October, November, December"
msgstr "janvier, février, mars, avril, mai, juin, juillet, août, septembre, octobre, novembre, décembre"

#: Orchard.Core.Shapes.DateTimeShapes
#| msgid "Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec"
msgctxt "Orchard.Core.Shapes.DateTimeShapes"
msgid "Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec"
msgstr "janv., févr., mars, avr., mai, juin, juil., août, sept., oct., nov., déc."

#: Orchard.Core.Shapes.DateTimeShapes
#| msgid "Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday"
msgctxt "Orchard.Core.Shapes.DateTimeShapes"
msgid "Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday"
msgstr "dimanche, lundi, mardi, mercredi, jeudi, vendredi, samedi, dimanche"

#: Orchard.Core.Shapes.DateTimeShapes
#| msgid "Sun, Mon, Tue, Wed, Thu, Fri, Sat"
msgctxt "Orchard.Core.Shapes.DateTimeShapes"
msgid "Sun, Mon, Tue, Wed, Thu, Fri, Sat"
msgstr "dim., lun., mar., mer., jeu., ven., sam."

#: Orchard.Core.Shapes.DateTimeShapes
#| msgid "Su, Mo, Tu, We, Th, Fr, Sa"
msgctxt "Orchard.Core.Shapes.DateTimeShapes"
msgid "Su, Mo, Tu, We, Th, Fr, Sa"
msgstr "di, lu, ma, me, je, ve, sa"

#: Orchard.Core.Shapes.DateTimeShapes
#| msgid "M/d/yyyy"
msgctxt "Orchard.Core.Shapes.DateTimeShapes"
msgid "M/d/yyyy"
msgstr "d/M/yyyy"

#: Orchard.Core.Shapes.DateTimeShapes
#| msgid "h:mm tt"
msgctxt "Orchard.Core.Shapes.DateTimeShapes"
msgid "h:mm tt"
msgstr "H:mm"

#: Orchard.Core.Shapes.DateTimeShapes
#| msgid "MMM d yyyy h:mm tt"
msgctxt "Orchard.Core.Shapes.DateTimeShapes"
msgid "MMM d yyyy h:mm tt"
msgstr "d MMM yyyy H:mm"

#: Orchard.Core.Shapes.DateTimeShapes
#| msgid "firstDay: 1"
msgctxt "Orchard.Core.Shapes.DateTimeShapes"
msgid "firstDay: 1"
msgstr "firstDay: 1"

#: Orchard.Core.Shapes.DateTimeShapes
#| msgid "isRTL: false"
msgctxt "Orchard.Core.Shapes.DateTimeShapes"
msgid "isRTL: false"
msgstr "isRTL: false"

#: Orchard.Core.Shapes.DateTimeShapes
#| msgid "showMonthAfterYear: false"
msgctxt "Orchard.Core.Shapes.DateTimeShapes"
msgid "showMonthAfterYear: false"
msgstr "showMonthAfterYear: false"

#: Orchard.Core.Shapes.DateTimeShapes
#| msgid "yearSuffix: "
msgctxt "Orchard.Core.Shapes.DateTimeShapes"
msgid "yearSuffix: "
msgstr "yearSuffix: "

In my case, dates are now correctly displayed using french preferences.

Coordinator
Mar 16, 2012 at 6:56 PM

This very new addition is for 1.4.1. Nice discovery.

Developer
Mar 16, 2012 at 10:19 PM

I've opened a discussion with an issue that might be related.

BTW such new string will eventually be included in the online translation tool, right?

Mar 17, 2012 at 8:40 AM
Piedone wrote:

I've opened a discussion with an issue that might be related.

BTW such new string will eventually be included in the online translation tool, right?

I didn't find some translations in the online translation tool, like projector module !?

Developer
Mar 17, 2012 at 11:07 AM

I think there are some technical difficulties with importing to the online tool, hence the delay.

Mar 21, 2012 at 1:29 PM

This datetime localization will be a great feature once we've got the entries in the .po files.  I've been playing with DateTime fields & for some reason I had to use 

#: Orchard.Core.Shapes.Localization.DateTimeLocalization

instead of

#: Orchard.Core.Shapes.DateTimeShapes (as per styx31, thankyou)

to get my en-AU culture working.

Jun 6, 2013 at 11:17 PM
Edited Jun 6, 2013 at 11:22 PM
Using Orchard 1.6.1 in mid-2013, I had to use a slightly different approach. Perhaps this will help others.

Example in view:
@Display.DateTime(DateTimeUtc: DateTime.Now.ToUniversalTime(), CustomFormat: T("M/d/yyyy"))
French language orchard.core.po file:
#| msgid "January, February, March, April, May, June, July, August, September, October, November, December"
msgid "January, February, March, April, May, June, July, August, September, October, November, December"
msgstr "janvier, février, mars, avril, mai, juin, juillet, août, septembre, octobre, novembre, décembre"

#| msgid "Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec"
msgid "Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec"
msgstr "janv., févr., mars, avr., mai, juin, juil., août, sept., oct., nov., déc."

#| msgid "Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday"
msgid "Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday"
msgstr "dimanche, lundi, mardi, mercredi, jeudi, vendredi, samedi, dimanche"

#| msgid "Sun, Mon, Tue, Wed, Thu, Fri, Sat"
msgid "Sun, Mon, Tue, Wed, Thu, Fri, Sat"
msgstr "dim., lun., mar., mer., jeu., ven., sam."

#| msgid "Su, Mo, Tu, We, Th, Fr, Sa"
msgid "Su, Mo, Tu, We, Th, Fr, Sa"
msgstr "di, lu, ma, me, je, ve, sa"

#| msgid "M/d/yyyy"
msgid "M/d/yyyy"
msgstr "d'/'M'/'yyyy"

#| msgid "h:mm tt"
msgid "h:mm tt"
msgstr "H:mm"

#| msgid "MMM d yyyy h:mm tt"
msgid "MMM d yyyy h:mm tt"
msgstr "d MMM yyyy H:mm"

#| msgid "firstDay: 1"
msgid "firstDay: 1"
msgstr "firstDay: 1"

#| msgid "isRTL: false"
msgid "isRTL: false"
msgstr "isRTL: false"

#| msgid "showMonthAfterYear: false"
msgid "showMonthAfterYear: false"
msgstr "showMonthAfterYear: false"

#| msgid "yearSuffix: "
msgid "yearSuffix: "
msgstr "yearSuffix: "