2009/08/13

osCommerce and setlocale

Filed under: osCommerce Coding — Tags: , — eCartz @ 20:24  Share/Bookmark  Delicious  StumbleUpon  WordPress  Twitter  LinkedIn

If you look in the osCommerce language files, there is often a line like

@setlocale(LC_TIME, ‘en_US.ISO_8859-1′);

What this does, when it works, is it sets the PHP time handling functions to use the specified locale’s format.  For many installs, this is unnecessary, as the server default will be correct.  Not infrequently, the locale will be invalid for the server, so the server uses the default.  If the default is correct, then no problem.

Interestingly, you can also use setlocale for other things, including number format.  However, sometimes you do not want to do so.  For example, in the osCommerce file includes/classes/order.php we have:

str_replace(‘.’, ”, $products_tax)

This works great in the US and other countries that use the period as the separator between the integer part and the decimal part of a number.  This works less well in countries like Denmark where the separator is a comma.  Therefore, in Denmark, you want to avoid setting the locale LC_NUMERIC or LC_ALL to the correct local value.  It can break osCommerce.

Sometimes it’s wrong to be right.

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

You can log in to post a comment, or just fill out your name and email.

Powered by WordPress