A tip on setlocale()

I’m always looking for ways to better integrate my Windows development environment and UNIX production servers (one way being virtual hosts). One of the few remaining inconveniences was setting the locale with the PHP command setlocale(). Setting the locale is necessary to adapt to regional differences with number and time formats, for example. The problem is that on my Windows box, I must use 3-letter-code according to ISO 3166-Alpha-3 like ‘deu’, whereas the UNIX systems I work with need a combined region/language setting like ‘de_DE’.

Fortunately, as I discovered yesterday, starting with PHP 4.3.0 (and higher), you can specify a list of locale arguments for setlocale(). If the first locale does not work, all following parameters are tried until the action is successfull. So, instead of writing:

if ($_SERVER['SERVER_NAME'] == 'localhost') {
setlocale(LC_ALL, 'deu');
}
else {
setlocale(LC_ALL, 'de_DE');
}

I can now write:

setlocale(LC_ALL, 'de_DE', 'deu'); 

Neat. Do you have other tips for better integrating development on Windows and UNIX?


About this entry