CakePHP supports LC_TIME translations since version 1.3 and since it took me some time to completely figure out the logic behind it I am storing my notes here as a mental reminder to self (again).
First things first… make sure you read the i18n paragraph on LC_TIME in the Book to get some basic understanding of what we are trying to do here.
Preparing for LC_TIME
For __c(), $this->Time->format() and $this->Time->i18nFormat() to work:
- create a file called /app/locale/dut/LC_TIME
- on your local Linux workstation open /usr/share/i18n/locales/nl_NL
- copy everything between LC_TIME and END LC_TIME to the file created in step 1 and save that file
Note: make sure to add the escape_char and comment_char definitions to your LC_TIME file as well or your setup will not be fully functional (see this page for more info):
comment_char % escape_char /
There is no need to use php’s strftime() if you consistently stick to using the CakePHP functions mentioned above. However, if you do need to get strftime() up and running you should add the following line to one of your controllers.
Please note (and understand) that this will use your server’s locales and NOT your manually created Cake LC_TIME file.
Testing your LC_TIME setup
Add the following lines to one of your views (and make sure the TimeHelper is available):
$timestamp = time(); $timestring = $this->Time->format('Y-m-d H:i:s', $timestamp); $months = __c('mon', 5 ,true); pr("Timestamp = $timestamp"); pr("Timestring = $timestring"); pr("strftime() translated = " . strftime("%A %e %B %Y", strtotime($timestring))); pr("i18nFormat translated = " . $this->Time->i18nFormat($timestring, "%A %e %B %Y")); pr("Time::format translated = " . $this->Time->format($timestring, '%A %e %B %Y')); pr($months);
If your setup is fully operational it should display the following LC_TIME translations:
Timestamp = 1292417839 Timestring = 2010-12-15 13:57:19 strftime() translated = Wednesday 15 December 2010 i18nFormat translated = woensdag 15 december 2010 Time::format translated = woensdag 15 december 2010 Array (  => januari  => februari  => maart  => april  => mei  => juni  => juli  => augustus  => september  => oktober  => november  => december )
Note: you might have spotted that the strftime() translation is not translated. This is intentional since I always stick to Cake methods. See the paragraph on strftime() if you do need to use that function.
Enjoy your time translations