Setting @@lc_time_names

Archived from the Xataface Users forum.

Cabeza — Fri Oct 05, 2012 8:57 am

Steve,
Any suggestion as to where would be the proper place in the app to insert the ref statement so that the server serves time names in languages other than English?
Thanks.


Cabeza — Tue Oct 09, 2012 12:39 am

Steve,
I am going to look into sending this as a mysql_query or df_query via the app’s beforeHandleRequest() on conf_ApplicationDelegate, but I would appreciate your comments anyway.
Thanks


shannah — Thu Oct 11, 2012 6:29 am

Yes. Put this inside a mysql_query.


Cabeza — Sat Oct 13, 2012 4:33 am

Thanks Steve. It works, with caveats, see below.
For those who may have been following this thread, passing the setting to the MySQL session via

(on conf/ApplicationDelegate.php)

Code: Select all
class conf_ApplicationDelegate { //...other stuff     function beforeHandleRequest(){         $app = Dataface_Application::getInstance();         $query_lc = "SET @@lc_time_names = 'es_ES'";         $result_lc = mysql_query($query_lc, df_db());         //...     }    //... }

works, but only sets the output to whatever locale you choose when the output is managed by MySQL’s date format functions. When using php’s format functions this setting is of little value. (obvious in hindsight, but not on my first rookie attempt…)
Next step is to try to complete the circle via php’s setlocale() and will eventually revert here.


Cabeza — Sat Oct 13, 2012 5:40 am

(the story goes on…)
adding

Code: Select all
$lc_es = setlocale(LC_TIME, 'es_ES.UTF-8');

on beforeHandleRequest() takes care of the php output strings, but it also means that uses of date() have to be refactored to strftime(). Date() is English only and takes no hints from setlocale().
There are a few things to take care when using setlocale() (Check php.net for the nitty gritty). The most important for me -and as warned by Lodovico Grossi @ http://us2.php.net/manual/en/function.setlocale.php- is that using LC_ALL may make a mess of the strings used on mysql_query() calls, so watch out. That is the reason why I went for the less greedy LC_TIME.

Hope it helps.

Xataface version: 1.3.2 on OSX 10.8.x Apache 2.2.22 php 5.3 MySQL 5.5.16