landitus Posted November 8, 2011 Share Posted November 8, 2011 Hi all! As always, a pleasure working with PW! But I'm stuck with the following. I have a blog-type page where each entry has a date time field. I've configured the date output as: "j \d\e F \d\e Y". But the month is shown in English (ex. November) I need to use the date in spanish, but I've read some php docs and they say I should use setlocale with strftime. But the output date I get from PW should be as an Unix timestamp I believe. How would you approach this? Link to comment Share on other sites More sharing options...
ryan Posted November 8, 2011 Share Posted November 8, 2011 Try this where you output the date: <?php setlocale(LC_TIME, 'es_ES'); // substitute your locale if not es_ES echo strftime('%e de %B de %Y', $page->getUnformatted('date')); // substitute your date field name This should produce the following output for today's date: 8 de noviembre de 2011 We're going to be providing localization support for the date field with ProcessWire 2.2, but the method described here will continue to be backwards compatible. Note you can also put the setlocale() part in your /site/config.php if you prefer. What locale you can use depends somewhat on what are installed on your server. I think that es_ES (or es_ES.UTF-8) is fairly standard, but if you want to get a list of locales you can type this in the unix shell: locale -a 1 Link to comment Share on other sites More sharing options...
apeisa Posted November 8, 2011 Share Posted November 8, 2011 Just 5 min ago used setlocale for finnish content. Had to install it first (on ubuntu): sudo apt-get install language-pack-fi-base and after that this spell did the magic: setlocale(LC_ALL, array('fi_FI.UTF-8','fi_FI@euro','fi_FI','finnish')); I found help from here: http://www.php.net/manual/en/function.setlocale.php#90919 Actually on ubuntu it seems that only different en_ locales are installed by default. Probably most web hosts have most popular languages covered. Link to comment Share on other sites More sharing options...
landitus Posted November 8, 2011 Author Share Posted November 8, 2011 Ryan, it worked perfectly! The key was the getUnformatted date! I ended up placing this i config.php: $config->timezone = 'America/Argentina/Buenos_Aires'; setlocale(LC_ALL, 'es_ES'); Thank you very much!!! Link to comment Share on other sites More sharing options...
apeisa Posted February 10, 2012 Share Posted February 10, 2012 Just noticed that setlocale() stops working if you have multilang support installed.. and this is probably pretty common situation setlocale(LC_ALL, 0) returns C, no matter what you set it before. Not sure if this is related: http://stackoverflow.com/questions/3398113/php-gettext-problems Link to comment Share on other sites More sharing options...
ryan Posted February 10, 2012 Share Posted February 10, 2012 Actually LanguageSupport includes a setLocale setting, but it needs to be defined with the language pack. If you go into Setup > Languages > [your language] > add translation file > Then paste in: /wire/modules/LanguageSupport/LanguageSupport.module You'll see a field come up where you can set the locale. Maybe I should have this disabled by default? (if the translation doesn't define it) 1 Link to comment Share on other sites More sharing options...
apeisa Posted March 29, 2012 Share Posted March 29, 2012 I think that disabling should be fine. This is pretty hard one to solve if one doesn't know that this file has settings like that. (But it is great to have as a setting indeed!). Link to comment Share on other sites More sharing options...
ryan Posted March 29, 2012 Share Posted March 29, 2012 Just to make sure I understand correctly. Do you think it's best to replace this (in LanguageSupport.module): setlocale(LC_ALL, $this->_('C')); with this? $locale = $this->_('none'); if($locale != 'none') setlocale(LC_ALL, $locale); The above would only call setlocale() if the language defined a locale in the translations. Link to comment Share on other sites More sharing options...
apeisa Posted March 29, 2012 Share Posted March 29, 2012 Yes, I think that would be better. Link to comment Share on other sites More sharing options...
ryan Posted March 29, 2012 Share Posted March 29, 2012 Sounds good, I will update. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now