Question

The following issue occurs with apache on Ubuntu 13.04(not sure about other OS's) I tried with fr_LU too but to no avail

Doesn't work -returns NaN

setlocale(LC_MONETARY, 'fr_FR.UTF-8');
$currency_formatter = NumberFormatter::create(setlocale(LC_MONETARY, "0"), NumberFormatter::CURRENCY);
$currency_formatter->formatCurrency(100, 'USD');

What am I missing here?

Result for locale -a on my machine is as follows:

  C
    C.UTF-8
    de_AT.utf8
    de_BE.utf8
    de_CH.utf8
    de_DE.utf8
    de_LI.utf8
    de_LU.utf8
    en_AG
    en_AG.utf8
    en_AU.utf8
    en_BW.utf8
    en_CA.utf8
    en_DK.utf8
    en_GB.utf8
    en_HK.utf8
    en_IE.utf8
    en_IN
    en_IN.utf8
    en_NG
    en_NG.utf8
    en_NZ.utf8
    en_PH.utf8
    en_SG.utf8
    en_US
    en_US.iso88591
    en_US.utf8
    en_ZA.utf8
    en_ZM
    en_ZM.utf8
    en_ZW.utf8
    fr_BE.utf8
    fr_CA.utf8
    fr_CH.utf8
    fr_FR
    fr_FR.iso88591
    fr_FR.utf8
    fr_LU.utf8
    ja_JP.utf8
    POSIX
    zh_CN.utf8
    zh_SG.utf8
Was it helpful?

Solution

Followed a comment at https://bugs.php.net/bug.php?id=54538 which goes as follows: "I have observed a workaround. Setting LC_MESSAGES does not affect NumberFormatter and is sufficient for gettext translations at the same time."

I commented It is a workaround and it worked for me. This is how my code looks after the change

putenv('LC_MESSAGES='.$locale);
setlocale(LC_MESSAGES, $locale);
setlocale(LC_TIME, $locale);
//Don't set LC_NUMERIC and LC_MONETARY as these may interfere with number formatter and cause to return NaN(https://bugs.php.net/bug.php?id=54538)
//setlocale(LC_NUMERIC, $locale);
//setlocale(LC_MONETARY, $locale);

$currency_formatter = NumberFormatter::create(setlocale(LC_MESSAGES, "0"), NumberFormatter::CURRENCY);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top