Search code examples
phplocale

setlocale "nl" working on one install and not on other


On one of my machines (with xampp for windows, xampp-win32-1.8.3-2-VC11-installer, php 5.5.6) this code returns "string(2) 'nl'":

var_dump(setlocale(0, 'nl'));

While on another machine with IIS (and php 5.4) this returns "bool(false)".

I tried the site http://setlocale.onlinephpfunctions.com/ and on their 5.5.5 this also returns "bool(false)".

What influences this behaviour? Is it because xampp has hidden information somewhere that my (more bare) install on IIS lacks?


Solution

  • This is a known bug: https://bugs.php.net/bug.php?id=66265

    I can reproduce the problem between XAMPP 1.8.2 and 1.8.3. Which use PHP 5.4.19 and PHP 5.5.6 respectively. The first correctly loads any PO file i ask it to, the latter always loads nl_NL no matter what parameters i use. My Windows OS is dutch.

    Ofcourse this wont solve your problem yet, but going there (and add your vote) may help getting this resolved.


    And many answers claim that the locale must be installed on the OS for the PO to work. Not true.

    That simply is not true. My PHP file only needed the PO files to exist, and it worked fine for every locale i tried. Both on a Windows 7 and Windows 8.1 computer, both dutch by default. I can have my PHP file use german, french, english, and dutch locale files.

    These all worked fine, the PO files where loaded and the entire PHP page was shown in the chosen language:

    // All these lines worked fine with PHP 5.4.19
    putenv('LC_ALL=de_DE');  setlocale(LC_MESSAGES, 'de_DE'); // German
    putenv('LC_ALL=fr_FR');  setlocale(LC_MESSAGES, 'fr_FR'); // French
    putenv('LC_ALL=en_UK');  setlocale(LC_MESSAGES, 'en_UK'); // English
    putenv('LC_ALL=nl_NL');  setlocale(LC_MESSAGES, 'nl_NL'); // Dutch
    

    Then i tried PHP 5.5.6 and the same commands stopped working. The page now always (!) shows the nl_NL locale. Executing getlocale(LC_ALL,0) returns Dutch_Netherlands.1252 which is the OS default language. Which somehow makes my PHP always use the nl_NL PO files.

    So to put all those answers to rest: the OS does not have to have the locale installed, the PO files work fine without in PHP 5.4.19, but not in PHP 5.5.6.