Jump to content

output date language


vxda
 Share

Recommended Posts

Hi,

I have a problem with outputing months names in Polish language,
Im using date filedtype, choosing date with datepicker and then outputing it in my template.

i spend some times reading forums, in example this Topic:
http://processwire.com/talk/topic/1751-cant-get-pw-to-output-german-month-names/

None of things work for me.

in config.php

$config->timezone = 'Europe/Poland';

in wire\modules\LanguageSupport\LanguageSupport.module

	if($locale != '0') setlocale(LC_ALL, 'pl_PL '); 

Still have english month names, what im doing wrong ?

Regars
Paweł

Link to comment
Share on other sites

First run this on your server:

<?php
echo '<hr>test WINDOWS server for locales';

/* try different possible locale names for english GB as of PHP 4.3.0 */
echo '<p>';
$loc_en = setlocale(LC_ALL, 'english_gbr', 'english_britain', 'english_england', 'english_great britain', 'english_uk', 'english_united kingdom', 'english_united-kingdom');
echo "Preferred locale for english GB on this system is '$loc_en'";
echo '<br/>' . strftime("%A %d %B %Y", mktime(0, 0, 0, 12, 22, 1978));

/* try different possible locale names for english USA as of PHP 4.3.0 */
echo '<p>';
$loc_enusa = setlocale(LC_ALL, 'english_usa', 'english_america', 'english_united states', 'english_united-states', 'english_us');
echo "Preferred locale for english USA on this system is '$loc_enusa'";
echo '<br/>' . strftime("%A %d %B %Y", mktime(0, 0, 0, 12, 22, 1978));

/* try different possible locale names for german as of PHP 4.3.0 */
echo '<p>';
$loc_de = setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'deu_deu');
echo "Preferred locale for german on this system is '$loc_de'";
echo '<br/>' . strftime("%A %d %B %Y", mktime(0, 0, 0, 12, 22, 1978));

/* try different possible locale names for spanish as of PHP 4.3.0 */
echo '<p>';
$loc_es = setlocale(LC_ALL, 'esp_esp', 'esp_spain', 'spanish_esp', 'spanish_spain');
echo "Preferred locale for spanish on this system is '$loc_es'";
echo '<br/>' . strftime("%A %d %B %Y", mktime(0, 0, 0, 12, 22, 1978));

/* try different possible locale names for dutch as of PHP 4.3.0 */
echo '<p>';
$loc_nl = setlocale(LC_ALL, 'nld_nld');
echo "Preferred locale for dutch on this system is '$loc_nl'";
echo '<br/>' . strftime("%A %d %B %Y", mktime(0, 0, 0, 12, 22, 1978));
?>

It will show you what setlocale setting your server accepts. I had to use "swedish_sweden" on my local xampp server and "sv_SE" on the live server.

In your config.php put this:

$config->timezone = 'Europe/Stockholm';
setlocale(LC_ALL, 'sv_SE');

Modify to your needs of course.

And finally use this to output the date:

<?php echo strftime("%e %B %Y", $page->getUnformatted("date"));?>

Hope this helps!

  • Like 2
Link to comment
Share on other sites

Hi thank you for such qucik answer.

From code u give me i get this:

test WINDOWS server for locales

Preferred locale for english GB on this system is 'English_United Kingdom.1252'
Friday 22 December 1978

Preferred locale for english USA on this system is 'English_United States.1252'
Friday 22 December 1978

Preferred locale for german on this system is 'German_Germany.1252'
Freitag 22 Dezember 1978

Preferred locale for spanish on this system is 'Spanish_Spain.1252'
viernes 22 diciembre 1978

Preferred locale for dutch on this system is 'Dutch_Netherlands.1252'
vrijdag 22 december 1978

Preferred locale for polish on this system is 'Polish_Poland.28592'
pi�tek 22 grudzie� 1978 

the last one is in polish but without polish chars.

My code looks like this:


echo "<div class='span2'>".
	"<div class='que'>{$e->que}<p>KOLEJKA</p></div>".
	"<div class='date'>{$e->date}</div>".
	"</div>".
	"<div class='span2'>".
		"<div class='team1'>".
			"<div class='pic'><img src='{$e->logo1->url}' alt='{$e->title}' /></div>".
			"<div class='name'>{$e->team_name1}</div>".
			"<div class='table'>w tabeli: <span>{$e->team_table1}</span></div>".
		"</div>".
		"<div class='versus'>VS</div>".
			"<div class='team2'>".
				"<div class='pic'><img src='{$e->logo2->url}' alt='{$e->title}' /></div>".
				"<div class='name'>{$e->team_name2}</div>".
				"<div class='table'>w tabeli: <span>{$e->team_table2}</span></div>".
			"</div>".
"</div>";

My date is on the 4th row.

what i need to do to get my date correct. Ty

Link to comment
Share on other sites

Hi thank you for such qucik answer.

From code u give me i get this:

test WINDOWS server for locales

Preferred locale for english GB on this system is 'English_United Kingdom.1252'
Friday 22 December 1978

Preferred locale for english USA on this system is 'English_United States.1252'
Friday 22 December 1978

Preferred locale for german on this system is 'German_Germany.1252'
Freitag 22 Dezember 1978

Preferred locale for spanish on this system is 'Spanish_Spain.1252'
viernes 22 diciembre 1978

Preferred locale for dutch on this system is 'Dutch_Netherlands.1252'
vrijdag 22 december 1978

Preferred locale for polish on this system is 'Polish_Poland.28592'
pi�tek 22 grudzie� 1978 

the last one is in polish but without polish chars.

My code looks like this:


echo "<div class='span2'>".
	"<div class='que'>{$e->que}<p>KOLEJKA</p></div>".
	"<div class='date'>{$e->date}</div>".
	"</div>".
	"<div class='span2'>".
		"<div class='team1'>".
			"<div class='pic'><img src='{$e->logo1->url}' alt='{$e->title}' /></div>".
			"<div class='name'>{$e->team_name1}</div>".
			"<div class='table'>w tabeli: <span>{$e->team_table1}</span></div>".
		"</div>".
		"<div class='versus'>VS</div>".
			"<div class='team2'>".
				"<div class='pic'><img src='{$e->logo2->url}' alt='{$e->title}' /></div>".
				"<div class='name'>{$e->team_name2}</div>".
				"<div class='table'>w tabeli: <span>{$e->team_table2}</span></div>".
			"</div>".
"</div>";

My date is on the 4th row.

what i need to do to get my date correct. Ty

Put this in your config.php:

setlocale(LC_ALL, 'Polish_Poland');

You could try changing this:

"<div class='date'>{$e->date}</div>".

to:

"<div class='date'>" . strftime("%e %B %Y", $e->getUnformatted("date")) . "</div>".

I'm not a programmer so this could be totally wrong.

  • Like 1
Link to comment
Share on other sites

There are two errors in your first post, not sure if these are just typos here:

1) Like Kongondo said, Europe/Poland does not exist: http://php.net/manual/en/timezones.europe.php

Change to: "Europe/Warsaw"

2) There is a space here which should be removed:

setlocale(LC_ALL, 'pl_PL '); 
 

On my server, I had to call setlocale like this, maybe this works for you:

setlocale(LC_ALL, 'pl_PL.UTF-8');
  • Like 1
Link to comment
Share on other sites

  • 4 weeks later...

My solution, which works nicely: I put the following code on the top of my template. (example for French as default, German and English)

$date_lang = array();
switch ($user->language->name) {
case 'en':
setlocale(LC_ALL, 'en_GB');
$date_lang[0] = "%A %B %eth %Y at %I:%M %p";
$date_lang[1] = "%B %eth %Y";
$date_lang[2] = "%I:%M %p";
$date_lang[3] = "%A";
break;

case 'fr':
setlocale(LC_ALL, 'fr_FR');
$date_lang[0] = "%A %e %B %Y à %kh%M";
$date_lang[1] = "%e %B %Y";
$date_lang[2] = "%kh%M";
$date_lang[3] = "%A";
break;

case 'de':
setlocale(LC_ALL, 'de_DE');
$date_lang[0] = "%A, den %e. %B %Y um %k.%Mh";
$date_lang[1] = "%e. %B %Y";
$date_lang[2] = "%k.%Mh";
$date_lang[3] = "%A";
break;

default:
setlocale(LC_ALL, 'fr_FR');
$date_lang[0] = "%A %e %B %Y à %kh%M";
$date_lang[1] = "%e %B %Y";
$date_lang[2] = "%kh%M";
$date_lang[3] = "%A";
}


Then I created a page field, where I store a date unformatted (go to setup->fields->mydatefield->details-> date output format ->"None").

getUnformatted() is only needed, if the date is stored formatted.
 

"<div class='date'>" . strftime("%e %B %Y", $e->getUnformatted("date")) . "</div>".


Finally I can insert the date like

echo strftime($date_lang[0], $mydatefield);
/* output(de): Freitag, den 11. Oktober 2013 um 12.52h
 * output(fr): Vendredi 11 octobre 2013 à 12h46
 * output(en): Friday October 11th 2013 at 12:46 pm
 */

echo strftime($date_lang[1], $mydatefield);
/* output(de): 11. Oktober 2013
 * output(fr): 11 octobre 2013
 * output(en): October 11th 2013
*/

echo strftime($date_lang[2], $mydatefield);
/* output(de): 12.52h
 * output(fr): 12h52
 * output(en): 12:52 pm
 */

echo strftime($date_lang[3], $mydatefield());
/* output(de): Freitag
 * output(fr): Vendredi
 * output(en): Friday
*/ 

Maybe you have to check out which string in setlocale is working on your Server. Try different:

setlocale(LC_ALL, array('fi_FI.UTF-8','fi_FI@euro','fi_FI','finnish'));
//put out the first supported string
echo setlocale(LC_ALL, 0);
  • Like 6
Link to comment
Share on other sites

  • 3 months later...

Hello! I tested kixe's example but I get this date: 

1 February 1970

$date_lang = array();
switch ($user->language->name) {
case 'en':
setlocale(LC_ALL, 'en_GB.UTF-8');
$date_lang[0] = "%A %B %eth %Y at %I:%M %p";
$date_lang[1] = "%B %eth %Y";
$date_lang[2] = "%I:%M %p";
$date_lang[3] = "%A";
break;

case 'pt':
setlocale(LC_ALL, 'pt_PT.UTF-8');
$date_lang[0] = "%A %e %B %Y às %kh%M";
$date_lang[1] = "%e %B %Y";
$date_lang[2] = "%kh%M";
$date_lang[3] = "%A";
break;

case 'fr':
setlocale(LC_ALL, 'fr_FR.UTF-8');
$date_lang[0] = "%A, den %e. %B %Y à %k.%Mh";
$date_lang[1] = "%e. %B %Y";
$date_lang[2] = "%k.%Mh";
$date_lang[3] = "%A";
break;

default:
setlocale(LC_ALL, 'pt_PT.UTF-8');
$date_lang[0] = "%A %e %B %Y às %kh%M";
$date_lang[1] = "%e %B %Y";
$date_lang[2] = "%kh%M";
$date_lang[3] = "%A";
}

then

if($page->date_and_time) echo "<p>" . strftime($date_lang[1], $date_and_time) . "</p>"; else ;
I don't use this module but there a member talks about the 1970 date it here too: http://processwire.com/talk/topic/711-release-schedulepages/?p=45172
 
Did someone get this date output too?
 
edit: Looking now at Unix timestamp to solve this.
Edited by nfil
Link to comment
Share on other sites

  • 3 months later...

I'm developing a multilingual site with a simple blog, where I've to display date field in multiple languages on the frontend.

I've set here the setlocale value: wire--modules--languagesupport--languagesupport-module to hu_HU.utf8

I've set the date format for all languages, it works.

I'm using the ProcessWire multi-language support modul

I realized that when I change language, everything is translated on the frontend, except date fields :S

The date fields language only depends on the logged in (or guest) users language, not on the choosed language...

And this is my problem.

My workaround is this, but do you have any better solution?

I've put this code to my head.inc template file.

switch($user->language->name) {
	case 'default':
		setlocale (LC_ALL, 'C');
		break;
	case 'hu':
		setlocale (LC_ALL, 'hu_HU.utf8');
		break;
	case 'bg':
		setlocale (LC_ALL, 'bg_BG.utf8');
		break;
}

In this case I reached my goal, but I can not understand why is the setting in wire--modules--languagesupport--languagesupport-module.

It has no effect for the frontend...

Thank you for help!

Link to comment
Share on other sites

No need to post in two threads the same question.

It has an effect but only for backend and in backend only user language defined in profile is used. The locale is set in LanguageSupport.module init(), and Front-end language is determined in LanguageSupportPageNames.module in ready() which is way later than the locale. I'm not sure it's possible to change that easily as language in backend and it's locale needs to be set early that various parts are translated (at least I think). Language support on front-end works different and is an "after thought" in that it's build with hooks. But maybe some locale setting there in LanguageSupportPageNames would fix it but then we'd have redundant settings.

Also setting the locale in the backend has or had various issues with floats and date's as php date strtotime can't handle localized date strings, and floats , or . php also has problems. So I found it's easier and more convenient to set the locale as you did in the template, I use that too. I find it to cumbersome to set locale in a file somewhere hidden.

  • Like 1
Link to comment
Share on other sites

  • 4 weeks later...

Depending on how your server image is setup the locale might not be activated which means it won’t output translated vales. You can check what locales are installed on your (assuming this is a linux variant) terminal : locale -a

Do a quick google search to find the appropriate command to enable a locale on your system.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...