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:
With the set locale:
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.
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:
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.
Hi,
I don't understand. Where do you put this code ?
Brice
I don't understand. Where do you put this code ?
Brice
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:
This won't give you the localized names of months, though.
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.
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 :
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 :
And this my config/site.php :
Somebody can help me please ?
Thanks and sorry for my long post.
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>
Viewing 15 lines of 21 lines. View entire code block.
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]);
Viewing 15 lines of 91 lines. View entire code block.
And this my config/site.php :
Somebody can help me please ?
Thanks and sorry for my long post.
HI,
Try first with an extra line in cofig.php:
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):
Change ‘croatian’ to ‘fr_FR’ (or delete line if setlocale is in config.php).
Look to the line 83.
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).
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.
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).
Great it works. Thank you !
@thuic
what do you mean with config.php - config/site.php?
what do you mean with config.php - config/site.php?
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.
Ok I just replaced the view.php file from the date_nav block - no changes
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:
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
Does this help?
<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?
Thanks for your response. Now I know that we should not modify localization.php
@ patric: do you mean message.mo? - can't find language strings for the month in german message.po
The latest one does have the strings. look here:https://github.com/Concrete5-de/concrete5-de/tree/master/languages/d...
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??
Maybe you can tell ma what I can do to see geman month (Januar instead of january) in blog-index and date-nav??
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:
Thanks Patrick - that works in blog_index.php
I put the line
in config/site.php
In blocks/page_list/templates/blog_index.php I replaced the line (11):
with
and in line (27)
to
But i don't know how to do this in the date_nav block and in blog_entry.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
But i don't know how to do this in the date_nav block and in blog_entry.php
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.
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.
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.
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.
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:
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.
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');
Viewing 15 lines of 21 lines. View entire code block.
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.
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.
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.
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.