Search code examples
phplocale

How does setlocale() work on Windows?


Developing a multilingual application I'd like to output locale-correct numbers and dates. Testing on Win7 I'm failing with both:

setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'deu', 'de', 'ge', 'German_Germany.1251');
var_dump(localeconv());

Shows that the decimal character is . but should be , for German.

$f = 3.14;
echo($f);

Confirms 3.14 as output.

Regardless what I've tried for setting the locale I didn't have success. Similar results apply with number_format(). It does however work for dates, e.g. month names.

What is the correct way to setlocale() on Windows/ CLI?


Solution

  • Seems like this is a known problem with PHP since 5.3: https://bugs.php.net/bug.php?id=65230

    setlocale() should be avoided in favor of NumberFormatter whenever possible.