Report this

What is the reason for this report?

Locale not working on my Ubuntu DigitalOcean Droplet

Posted on September 13, 2013

I developed a PHP shopping cart for a website that has world wide sales. Because of it’s international traffic, I’m using setlocale() and localeconv() to display ‘USD’ next to all prices whenever the locale is not en_US. This works great when my code is hosted at places like Hostgator, Westhost, even GoDaddy, but it’s not working on my DigitalOcean “Droplet”. Here’s what I get from localeconv() from Hostgator:

$locale_info => Array (18) ( | [‘decimal_point’] = String(1) “.” | [‘thousands_sep’] = String(0) “” | [‘int_curr_symbol’] = String(4) "USD " | [‘currency_symbol’] = String(1) “$” | [‘mon_decimal_point’] = String(1) “.” | [‘mon_thousands_sep’] = String(1) “,” | [‘positive_sign’] = String(0) “” | [‘negative_sign’] = String(1) “-” | [‘int_frac_digits’] = Integer(1) 2 | [‘frac_digits’] = Integer(1) 2 | [‘p_cs_precedes’] = Integer(1) 1 | [‘p_sep_by_space’] = Integer(1) 0 | [‘n_cs_precedes’] = Integer(1) 1 | [‘n_sep_by_space’] = Integer(1) 0 | [‘p_sign_posn’] = Integer(1) 1 | [‘n_sign_posn’] = Integer(1) 1 | [‘grouping’] => Array (0) | ( | ) | [‘mon_grouping’] => Array (2) | ( | | [‘0’] = Integer(1) 3 | | [‘1’] = Integer(1) 3 | ) )

And here’s what it looks like on Disital Ocean: $locale_info => Array (18) ( | [‘decimal_point’] = String(1) “.” | [‘thousands_sep’] = String(0) “” | [‘int_curr_symbol’] = String(0) “” | [‘currency_symbol’] = String(0) “” | [‘mon_decimal_point’] = String(0) “” | [‘mon_thousands_sep’] = String(0) “” | [‘positive_sign’] = String(0) “” | [‘negative_sign’] = String(0) “” | [‘int_frac_digits’] = Integer(3) 127 | [‘frac_digits’] = Integer(3) 127 | [‘p_cs_precedes’] = Integer(3) 127 | [‘p_sep_by_space’] = Integer(3) 127 | [‘n_cs_precedes’] = Integer(3) 127 | [‘n_sep_by_space’] = Integer(3) 127 | [‘p_sign_posn’] = Integer(3) 127 | [‘n_sign_posn’] = Integer(3) 127 | [‘grouping’] => Array (0) | ( | ) | [‘mon_grouping’] => Array (0) | ( | ) )

I’m guessing there is something that I need to install/setup. Anybody know what?

I’m running LAMP on Ubuntu 12.04



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

work to me. Thanks.

Follow up: <br> <br>From an SSH commandline, “locale” produces: <br> <br>LANG=en_US.UTF-8 <br>LANGUAGE=en_US:en <br>LC_CTYPE=“en_US.UTF-8” <br>LC_NUMERIC=“en_US.UTF-8” <br>LC_TIME=“en_US.UTF-8” <br>LC_COLLATE=“en_US.UTF-8” <br>LC_MONETARY=“en_US.UTF-8” <br>LC_MESSAGES=“en_US.UTF-8” <br>LC_PAPER=“en_US.UTF-8” <br>LC_NAME=“en_US.UTF-8” <br>LC_ADDRESS=“en_US.UTF-8” <br>LC_TELEPHONE=“en_US.UTF-8” <br>LC_MEASUREMENT=“en_US.UTF-8” <br>LC_IDENTIFICATION=“en_US.UTF-8” <br>LC_ALL= <br>

I changed: <br> <br>setlocale(LC_MONETARY, ‘en_US’); <br> <br>to: <br> <br>setlocale(LC_MONETARY, ‘en_US.UTF-8’); <br> <br>And my shopping cart is no longer displaying ‘USD’ after the prices (which is what I designed it to do). Now I just have to find a way to test it with a non-US locale to see if the ‘USD’ suffixes return. <br>

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.