Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

[Solved] Getting template dates to display in French - how?


Go to End


5 Posts   1608 Views

Avatar
Gelert

Community Member, 14 Posts

12 August 2015 at 8:01pm

Edited: 12/08/2015 8:01pm

Single French language website so no need to switch languages on the fly.

In config.php:

i18n::set_locale('fr');
DateField::set_default_config('setLocale','fr');

Site is loading up fr.yml files fine.
The CMS database is being written to in French.

template.ss

<p class="date">
<span class="month">$FromDate.ShortMonth</span>
<span class="day">$FromDate.DayOfMonth</span>
<span class="year">$FromDate.Year</span>
</p>

class.php

	static $db = array (
		'FromDate' => 'Date',
	);

	public function getCMSFields() {
...
		$dateField = new DateField('FromDate');
		$dateField->setConfig('showcalendar', true);
		$dateField->setLocale('fr');
		$dateField->setConfig('jslocale', 'fr');
		$fields->addFieldToTab('Root.Main', $dateField);
...
}

Front end output:
AUG
28
2015

The back end CMS calendar is displaying in French but the front end doesn't seem to want to play ball.

How do I get Silverstripe to output AUG as AOÛT on the template.ss?

Is it something to do with the server locale? Anything to set in Apache?

Any help appreciated. All my searches have come up with nothing. I'm posting to the forum as a last resort.

Avatar
Pyromanik

Community Member, 419 Posts

12 August 2015 at 10:36pm

This is most unfortuantely because of: http://php.net/manual/en/datetime.format.php#refsect1-datetime.format-notes
You can however use: http://php.net/manual/en/function.strftime.php With the extracted timestamp from the SS_Datetime.

Thanks to swaiba for identifying a solution

Avatar
Gelert

Community Member, 14 Posts

12 August 2015 at 10:41pm

Thanks for the quick reply.

I've been messing with

$FromDate.FormatI18N('%A %e %B %Y')

on the template with no success.

I'll see if I can make strftime() work.

I'm guessing I need to setup a custom function in my class to use the PHP functions and return them back to my template as a string. I think that might work.

Avatar
Gelert

Community Member, 14 Posts

12 August 2015 at 11:01pm

I got it working.

In config.php I set:

DateField::set_default_config('setLocale','fr_FR');
setlocale(LC_ALL, "fr_FR");
setlocale(LC_TIME, "fr_FR");

and on the template

$FromDate.FormatI18N('%A %e %B %Y')

began to output in French.

I think I'm sorted now.

Avatar
Pyromanik

Community Member, 419 Posts

13 August 2015 at 2:45am

Cool, that seems like a nice and neat solution :)
Thanks for sharing.