Jump to content
vxda

output date language

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ł

Share this post


Link to post
Share on other sites

in config.php

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

Shouldn't this be Europe/Warsaw by the way?

  • Like 1

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Im wroking localy now and i cant get it right, i will try again after moving it to destination server.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Great, sorry about the duplicate questions, I thought more people would read it in different but similar topics. :)

Thank you for your quick answer, than I leave my code as wrote above...

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By snobjorn
      Here's my Norwegian language pack for ProcessWire. I've been adding translations over some time, to suit my own projects users needs.
      Last updated:
      2019/06/19 (June 19, 2019)
      Status:
      Not yet complete. Translations that non-superusers will see is prioritized.
      Name:
      ProcessWire-Norwegian-Language-Pack-nb-NO
      Translated using:
      ProcessWire 3.0.133 dev
      Number of files:
      189 wire files and 95 site files – ranging from just started to completely translated. The site files includes translation some free and some pro modules, see the complete list in the README.md at GitHub.
      Available at GitHub:
      https://github.com/snobjorn/processwire-norwegian-language-pack-nb-no
    • By louisstephens
      Hopefully this is the right place, if not, please move it to the proper sub. I installed the multi language module on my development (sandbox) set up not too long ago to test out a few things. From the start, I ran into some issues with dependencies not being met/installed, so I thought that I would simply just uninstall what had been. Unfortunately, that took me down a road of using some code in my home template to remove the modules (cant find it at the moment). After some struggling, I finally got it uninstalled, but it left behind 3 fields,
      language language_files language_files_site I thought that I could simply remove them from the languages template and then delete them, but I get the following error:

      I was wondering, is there a way to remove these using the api? I couldn't add any new users to the setup until I made "language" not required, but I was hoping to just remove all of the fields.
    • By Elchin
      Hi.
      I want select pages where now between date and end_date or now bigger than date and end_date is empty.
      I have five tried variants:
      $start = strtotime(date('Y-m-d') . " 00:00:00"); $results = $page->children("foo=(date<$start,date_end=''),bar=(date<$start,date_end>=$start),sort=-date,limit=12"); $start = strtotime(date('Y-m-d') . " 00:00:00"); $results = $page->children("date<$start,(date_end='',date_end>=$start),sort=-date,limit=12"); $start = strtotime(date('Y-m-d') . " 00:00:00"); $results = $page->children("date_end=''|date_end>=$start,date<$start,sort=-date,limit=12"); $start = strtotime(date('Y-m-d') . " 00:00:00"); $results = $page->children("!date_end|date_end>=$start,date<$start,sort=-date,limit=12"); $start = strtotime(date('Y-m-d') . " 00:00:00"); $results = $page->children("date_end>=$start|!date_end,date<$start,sort=-date,limit=12"); All this variants not worked for me and returned zero results.
    • By MateThemes
      Hello everyone.
      I have a question that i can't find a way to solve.
      I have following function in _uikit.php 
      $date = $page->get('date|createdStr'); $dateModified = $page->get('datemodified'); But I need to output the $date in to different formats.
      My further function looks like this
      // return the blog post article markup return " <div> <article class='uk-article blog-post $class'> <meta property='name' content='$page->title'> <meta property='author' typeof='Person' content='Arra Lifte Harmanschlag'> <meta property='dateModified' content='$dateModified'> <meta property='datePublished' content='$date'> <meta class='uk-margin-remove-adjacent' property='articleSection' content='News'> <div property='image' typeof='ImageObject'> $featuredBlogPostImage </div> $heading <ul class='mt25 uk-margin-remove-bottom uk-subnav uk-subnav-divider'> <li class='uk-article-meta'> <time datetime='$date'>$byline</time> </li> </ul> <div class='mt25' property='text'> $body </div> </article> </div> "; Now I need to output the meta property in this format 2019-03-02CET05:23:00 and then a normal date format that is displayed on the Homepage with 2. März 2019 without time.
      Can anybody help me?
      Thanks in advance.
    • By bartelsmedia
      "Deepl" is an unbelievably good (paid) text translation service, that mops the floor with Google Translate.
      They have an API and it would be awesome, if there would be a module, that would integrate it for easy content translation.
      It could be a right-click context menu on the language tab:

      It should ask from which of available other language it shall take translate from.
      What do you think?
×
×
  • Create New...