Author |
Message |
Gremmie
Former Moderator in Good Standing

Joined: Apr 06, 2006
Posts: 2415
Location: Iowa, USA
|
Posted:
Sun Nov 05, 2006 12:35 pm |
|
I'm writing a module, an event calendar, and this time I actually hope to release it to the world, so I'm being more careful about portability and trying to think about users other than myself.
As you can imagine, I need to work with month names, weekday names, and display times and dates in various formats. PHP has many functions that return month names, etc. as strings, but they rely on the locale that the server has set. Should I use these PHP functions? They sure make my life a bit easier. Or are there lots of people out there that run sites in one language with their server's locale being set to another? In that case, using language files or settings in a config database table may be better for them. Any thoughts on this? Thanks. |
|
|
|
 |
montego
Site Admin

Joined: Aug 29, 2004
Posts: 9457
Location: Arizona
|
Posted:
Sun Nov 05, 2006 8:47 pm |
|
I have been wrestling with the same issue myself. I have been considering moving to using language files. But, I was going to research it more... just haven't had the time. I had issues recently with Persian and one other lanuage. If you have control over your server environment, its "ok" to use the built-in functions (I believe). However, if you plan on distributing this, it could become problematic.
Unfortunately I do not have any solid advice for you (remember the "research" comment above? ) |
_________________ Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! |
|
|
 |
Guardian2003
Site Admin

Joined: Aug 28, 2003
Posts: 6799
Location: Ha Noi, Viet Nam
|
Posted:
Sun Nov 05, 2006 9:10 pm |
|
I have never even considered this but my gut feeling is to use language files.
There is potentially more individuals using shared hosting services in locations different to their home - or to put it another way, the server and the webmaster may well be within different time zones.
It would appear that the forums handle this pretty well with allowing the user to 'compensate' for the difference so it may be worth exploring how they have achieved this.
Something missing from most Calendars I have looked at is that they tend to NOT display the time zone - which might be really useful for global events.
If an event is scheduled for 18:00 hours, the user can really make an educated guess whether that is GMT, BST, UTC, EDT and so on. |
|
|
|
 |
montego

|
Posted:
Mon Nov 06, 2006 5:55 pm |
|
In case you are interested, phpBB uses the unix timestamp to store post time and then uses this function in includes/functions.php to format it:
Code:function create_date($format, $gmepoch, $tz)
{
global $board_config, $lang;
static $translate;
if ( empty($translate) && $board_config['default_lang'] != 'english' )
{
@reset($lang['datetime']);
while ( list($match, $replace) = @each($lang['datetime']) )
{
$translate[$match] = $replace;
}
}
return ( !empty($translate) ) ? strtr(@gmdate($format, $gmepoch + (3600 * $tz)), $translate) : @gmdate($format, $gmepoch + (3600 * $tz));
}
|
I had used this approach in my HTML Newsletter, but found at least two languages where it did not work. I have not had a chance to research this further unfortunately. |
|
|
|
 |
Gremmie

|
Posted:
Fri Nov 10, 2006 12:09 pm |
|
I just found out about the setlocale() function, but on second thought doesn't look too promising either. At first I thought I could let the user provide a locale string in a config table, and the script would call setlocale() at the beginning. But not every server is going to have all locales installed, and setting the locale is process wide, so another script in another thread maybe could override you.
I'm leaning towards using language files and/or schemes like you show, Montego, where you let your user specify a translation or something. |
|
|
|
 |
64bitguy
The Mouse Is Extension Of Arm

Joined: Mar 06, 2004
Posts: 1164
|
Posted:
Fri Nov 10, 2006 2:28 pm |
|
When dealing with international complexities and the fact that there is more than one calendar on the globe as well as rules for European summers and American DST rules, I suggest that one always simply reading the manual.
http://www.php.net/manual/en/ref.datetime.php
There are existing methods in Nuke and phpBB. You can either use those or write your own solution. I would also suggest simply looking at other calendar programs to see how they've handled events.
IMHO, it is to START by storing it as a timestamp in MySQL. Worry about the rest after that.
http://dev.mysql.com/doc/refman/5.0/en/datetime.html |
_________________ Steph Benoit
100% Section 508 and W3C HTML5 and CSS Compliant (Truly) Code, because I love compliance. |
|
|
 |
Gremmie

|
Posted:
Fri Nov 10, 2006 2:36 pm |
|
Well I have read the manual, I'm just debating on whether to rely on the locale or use language files/user specified translation (in case the user's language does not match his server's locale). |
|
|
|
 |
montego

|
Posted:
Sat Nov 11, 2006 6:39 am |
|
And, I have had issues with the core PHP functions around dates because of servers not having all the locales installed. I, too, will be investigating further, as I get time.
Gremmie, would appreciate reporting of any of your own findings along the way. I will too in kind. |
|
|
|
 |
64bitguy

|
Posted:
Sat Nov 11, 2006 9:05 am |
|
Well, I guess the part that I don't understand in the thread is if you are asking about the name translations of data values, or the actual data values themselves.
If we are talking about the name translation values, I would suggest using language files to convert the data values saved in MySQL; (Monday, Tuesday, Wednesday, etc...); however, the reflected values (let's say for GMT plus or minus whatever) is fixed math in the sense that these formulas for PHP conversions (as well as other languages) have already be written depending on which "Calendar" you are using. This is where I fall back to the statement of saving in MySQL first and then filter/manipulate the data values after that.
I must be lost. Can you help me catch up to where you are in understanding just what it is you are tying to do?
Thanks
Steph |
|
|
|
 |
fkelly
Former Moderator in Good Standing

Joined: Aug 30, 2005
Posts: 3312
Location: near Albany NY
|
Posted:
Sat Nov 11, 2006 9:34 am |
|
Interesting. In performance testing PHPnuke as part of RN2.10 development I have been noticing that the setlocale function is one of the big performance "hogs". It was kind of curious to me and I meant to look into it but never have until now.
What happens is that in Nuke you set a preference thru the admin screen that gets stored in the config table. The name of the field is "locale" and a sample value in a test system I have is "en_US". This value is read into a variable called $locale and the
Code:function formatTimestamp($time) {
global $datetime, $locale;
setlocale(LC_TIME, $locale);
|
formatTimeStamp function is called. It appears to me in testing that this gets executed once every "pass" thru Nuke for each user. It appears also that all this function does is return a value for $datetime. If eventually we could bypass the invocation of setlocale() we'd save a few milliseconds but no big deal I suppose. |
|
|
|
 |
Gremmie

|
Posted:
Sat Nov 11, 2006 12:00 pm |
|
Steph,
I am concerned with the formatting of day names, month names, time formats, strftime(), getdate(), etc. Of course I will use the PHP and MySQL facilities for doing time and date math, but its just the presentation of the results to the end user I am struggling with.
For example, my event calendar is going to by default display something like:
Today's Date: 11 November 2006
I can immediately see someone is going to hate that, and want:
November 11 2006
or
Nov. 11, 2006
or
11 Nov 2006
or who knows what they want in some other country.
The easy thing to do would be to provide a strftime() format string in a config table. I would read that out of the database and use that string in a call to strftime() to format the date they way they want. But that assumes the locale is all squared away. Should I be concerned about that? Are there a lot of people who run sites in one language but their server's locale is set to another? And maybe I could also read a locale string out of a config table and call setlocale() at the top of the script. But maybe that server doesn't support that locale. Maybe I am getting carried away with all these concerns. Thats why I was asking here.
As of this moment, I am leaning towards using language files. And perhaps providing some config table support like a strftime() string so the user can tell me how they want the date displayed (day first, month second, year third, etc). But then I would parse that string and use the language file constants (for example, to display the month name).
I dunno. I kind of think maybe I am getting wrapped around the axle on this.
Thanks for any advice. |
Last edited by Gremmie on Sat Nov 11, 2006 12:03 pm; edited 1 time in total |
|
|
 |
Gremmie

|
Posted:
Sat Nov 11, 2006 12:01 pm |
|
(oopsie......how do I delete a duplicate post??)  |
|
|
|
 |
Gremmie

|
Posted:
Sun Nov 12, 2006 10:47 am |
|
Well, as always, when you don't know what you are doing , and you don't have any hard requirements, you do something simple. Once I get this thing running and out the door I will probably be getting feedback from users, so I will let that steer me. So for now, I'll just use language files for names and hard code a format. |
|
|
|
 |
montego

|
Posted:
Mon Nov 13, 2006 6:57 am |
|
Good luck! Definitely report back the feedback. One of these days I'm going to dig into this... |
|
|
|
 |
|