Set locale on date - Multilanguage site

Permalink
I read a previous post about this, but it did not work! (It was suggesting to insert the local language in the site.php with an "if" statement if I remember right !?)

I instead, created a second template for the "news" feed called: news-fr. Within the view.php document I'm trying to merge the following, but without success;

Merging the concrete5 snippet:
$date = $cobj->getCollectionDatePublic('j, Y');

With the set locale:
setlocale (LC_TIME, 'fr_FR');
      $date = strftime("%B %Y");


What I require is to display the posted date stamp in french for the news feed under the french root.

thanks for all suggestions and/or tips.

Tallfrog
View Replies:
thuic replied on at Permalink Reply
thuic
In Croatian localization I find out that for some strange reason (for me – php newbie) working code must have instead country/language code (in my case 'hr_HR') full language description ie. 'croatian'.
setlocale (LC_TIME, 'croatian');
      $date = strftime("%B %Y");

I did't try that in news-page list yet – only in the current date block.
You can move first line of code to site.php.
Tallfrog replied on at Permalink Reply
Tallfrog
Anyone found a solution for this?

I would appreciate any type of tips or how to's on merging the setlocale with the$cobj.

Everything can be done :)

Wouldnt it be something like this:

setlocale (LC_TIME, 'fr_FR');
      $date = $cobj->getCollectionDatePublic(strftime("%e %B %Y"));
Tallfrog replied on at Permalink Reply
Tallfrog
Well, i found a solution thanks to google and research!
A member here posted an inquiry and within his post, my solution!

It results in:
setlocale (LC_TIME, 'fr_FR');
      $date = strftime("%e %B %Y", strtotime($cobj->getCollectionDatePublic()));
tacktack replied on at Permalink Reply
tacktack
Hi,

I don't understand. Where do you put this code ?

Brice
PatrickHeck replied on at Permalink Reply
PatrickHeck
Please note that this is not always reliable, since the locale has to be installed in your system.
You can also use the date constants defined in localization.php like DATE_APP_GENERIC_MDYT_FULL. (seehttps://github.com/concrete5/concrete5/blob/master/web/concrete/conf... )
So you could use:
$date = $cobj->getCollectionDatePublic(DATE_APP_GENERIC_MDYT_FULL);

This won't give you the localized names of months, though.
tacktack replied on at Permalink Reply
tacktack
Hi,

Why is it so difficult to adapt concrete5 in other language than english ?

You can see my website here :http://chiropratique.tack-tack.fr/actu/...

For dates in French on my articles, I did that in blocks/page_list/templates/blog_index.php :

<?php
defined('C5_EXECUTE') or die(_("Access Denied."));
$bh = Loader::helper('page_list_blog');
?>
<div class="ccm-page-list">
   <?php
   foreach ($cArray as $cObj) {
      $title = $cObj->getCollectionName();
      $link = $nh->getLinkToCollection($cObj);
      $author = $cObj->getVersionObject()->getVersionAuthorUserName();
      $date = $cObj->getCollectionDatePublic("U");
      setlocale(LC_TIME, "fr_FR");
   ?>
      <h3 class="ccm-page-list-title"><a href="<?php echo $link; ?>"><?php echo $title; ?></a></h3>
      <p class="info_post">Posté le <?php echo strftime('%A %e %B %Y',$date); ?> par <?php echo $author; ?></p>


I don't know if it's a good way to do this but it works.

But I can't the blocks "date_nav" in french.

This my file localization.php :
<?php 
defined('C5_EXECUTE') or die("Access Denied."); 
$u = new User();
Config::getOrDefine('SITE_LOCALE', 'fr_FR');
if ($u->getUserDefaultLanguage() != '') {
   define('ACTIVE_LOCALE', $u->getUserDefaultLanguage());
} else if (defined('LOCALE')) {
   define('ACTIVE_LOCALE', LOCALE);
} else {
   define('ACTIVE_LOCALE', SITE_LOCALE);
}
if (strpos(ACTIVE_LOCALE, '_') > -1) {
   $loc = explode('_', ACTIVE_LOCALE);
   if (is_array($loc) && count($loc) == 2) {
      define('LANGUAGE', $loc[0]);


And this my config/site.php :

<?php 
define('DB_SERVER', '***********');
define('DB_USERNAME', '***********');
define('DB_PASSWORD', '***********');
define('DB_DATABASE', '***********'); 
define('BASE_URL', '***********');
define('DIR_REL', '');
define('PASSWORD_SALT', '***********');
define('LOCALE', 'fr_FR');


Somebody can help me please ?

Thanks and sorry for my long post.
thuic replied on at Permalink Reply 1 Attachment
thuic
HI,
Try first with an extra line in cofig.php:
setlocale (LC_TIME, 'fr_FR');

Second, maybe attached Croatian template can help you. Pay attention to following:
I did not made any changes in localization.php (yet).
In my Date Nav view.php I have an extra line (6):
setlocale (LC_TIME, 'croatian');

Change ‘croatian’ to ‘fr_FR’ (or delete line if setlocale is in config.php).
Look to the line 83.
echo "\t <div class='section trigger ".$monthClosed." month".$month.'_'.$year."'>".t(iconv('ISO-8859-2', 'UTF-8', ucfirst (strftime("%B",mktime(0,0,0,$month,1,$year)))   ))."</div> \r \n";

The ucfirst() function converts the first character of a string to uppercase.
'ISO-8859-2' is referring to East European languages. Use ISO-8859-1 or ISO-8859-15 (Western European), see:http://www.w3schools.com/tags/ref_charactersets.asp...

To see this Date Nav at work go to my dev sitehttp://00-portal.graditeljsvratista.hr/hr/novosti... - and switch to English (both pages are using the same Date Nav view.php).
tacktack replied on at Permalink Reply
tacktack
Great it works. Thank you !
tsilbermann replied on at Permalink Reply
tsilbermann
@thuic

what do you mean with config.php - config/site.php?
thuic replied on at Permalink Reply
thuic
I mean, for date translations, as I described, you must ‘setlocale’ in your view.php file (i.e. in page list or datenav block), or in config.php file.
tsilbermann replied on at Permalink Reply
tsilbermann
Ok I just replaced the view.php file from the date_nav block - no changes
PatrickHeck replied on at Permalink Reply
PatrickHeck
Hi, I don't really understand wich part is not working, but the way you would write your code using the localization constants would be:
<p class="info_post">Posté le <?=$cObj->getCollectionDatePublic(DATE_APP_GENERIC_MDY_FULL)?> par <?php echo $author; ?></p>

No need to change anything in the localization.php file, but you need to have a current language file (messages.po) for french installed. There the appropriate date format will be described like
msgid "n/j/Y"
msgstr "j/n/Y"

Does this help?
tacktack replied on at Permalink Reply
tacktack
Thanks for your response. Now I know that we should not modify localization.php
tsilbermann replied on at Permalink Reply
tsilbermann
@ patric: do you mean message.mo? - can't find language strings for the month in german message.po
PatrickHeck replied on at Permalink Reply
PatrickHeck
The latest one does have the strings. look here:https://github.com/Concrete5-de/concrete5-de/tree/master/languages/d...
tsilbermann replied on at Permalink Reply
tsilbermann
Hm - I'm confused!

Maybe you can tell ma what I can do to see geman month (Januar instead of january) in blog-index and date-nav??
PatrickHeck replied on at Permalink Reply
PatrickHeck
This Method will not work if you want to display translated month names. For that you need to use strftime - But you need to have the localization files installed in the operating system of your server. This will print the name of the current month in the active locale:
$date = $cobj->getCollectionDatePublic("U");
setlocale(LC_TIME, LOCALE);
echo strftime('%B',$date);
tsilbermann replied on at Permalink Reply
tsilbermann
Thanks Patrick - that works in blog_index.php

I put the line
setlocale (LC_TIME, 'de_DE');

in config/site.php

In blocks/page_list/templates/blog_index.php I replaced the line (11):
$date = $cobj->getCollectionDatePublic('d.m.o');

with
$date = $cobj->getCollectionDatePublic("U");

and in line (27)
<?php  echo $date; ?>

to
<?php  echo strftime('%e. %b. %Y',$date); ?>


But i don't know how to do this in the date_nav block and in blog_entry.php
tsilbermann replied on at Permalink Reply
tsilbermann
If it is so difficult for "non PHP-nerds" to change the date format (month-names) a step by step tutorial would be helpful.

What I found out for Blog (list-fiew):

adding this code to to blog_index.php worked for me

setlocale (LC_TIME, 'de_DE');
$date = strftime("%e. %b. %Y", strtotime($cobj->getCollectionDatePublic()));

If someones opinion is that is nonsense - please describe how to make it better.
thuic replied on at Permalink Reply 1 Attachment
thuic
Hi,

Please find bunch of 'translated' Date Nav templates in attachment (German, Croatian, Czech, Finnish, French, Hungarian, Portuguese, Dutch and Swedish).

Upload and extract attached zip folder in Blocks folder (as always - in the root of your C5 installation), and delete unneccessery templates.

IMPORTANT: view.php have Java Script and CSS (that's because I noticed some problems with rendering when template is programatically inserted in page from Scrapbook). Delete <script> .... </script> and <styles> .... </styles> and re-link with original js and css in date_nav folders - if you like.

You can see templates at work on my temporary test site (100% clean installation without any modifications - on Linux web-server):http://test.huic.net/index.php/news/...

And for the end: I am not very good in PHP stuff. Maybe code is not clean enough.
thuic replied on at Permalink Reply
thuic
I JUST FIND HOW TO USE GETTEXT TRANSLATIONS FOR DAYS AND MONTHS!
The date nav has the months print out wrapped with the t() translation function. Nice, but C5 translation file is not armed with days and months.
Make false php document, something like this:

<?php
print t('Monday');
print t('Tuesday');
print t('Wednesday');
print t('Thursday');
print t('Friday');
print t('Saturday');
print t('Sunday');
print t('January');
print t('February');
print t('March');
print t('April');
print t('May');
print t('June');
print t('July');


Upload your dummy.php file somewhere in concrete directory… run poedit… translate dates and months. Update your local lang translations, clear cache and enjoy translated date nav.
TorstenKelsch replied on at Permalink Reply
TorstenKelsch
Your solution is by far the easiest, and it works perfectly! Thank you so much!

Just let me add the following explanation: The .mo file has to be uploaded to the languages folder, in my case it is /languages/de_DE/LC_MESSAGES. The name of the .mo file is not important, just take care you do not overwrite the existing file. Name it date.mo or whatever you like.

Again, thanks for posting your answer to this problem.