Question

Locale not working on my Ubuntu DigitalOcean Droplet

  • Posted on September 13, 2013
  • stlawsonAsked by stlawson

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


Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

work to me. Thanks.

Yeah, now, on my DigitalOcean Droplet, localconv() returns: <br> <br>$locale_info => Array (18) <br>( <br>| [‘decimal_point’] = String(1) “.” <br>| [‘thousands_sep’] = String(0) “” <br>| [‘int_curr_symbol’] = String(4) "USD " <br>| [‘currency_symbol’] = String(1) “$” <br>| [‘mon_decimal_point’] = String(1) “.” <br>| [‘mon_thousands_sep’] = String(1) “,” <br>| [‘positive_sign’] = String(0) “” <br>| [‘negative_sign’] = String(1) “-” <br>| [‘int_frac_digits’] = Integer(1) 2 <br>| [‘frac_digits’] = Integer(1) 2 <br>| [‘p_cs_precedes’] = Integer(1) 1 <br>| [‘p_sep_by_space’] = Integer(1) 0 <br>| [‘n_cs_precedes’] = Integer(1) 1 <br>| [‘n_sep_by_space’] = Integer(1) 0 <br>| [‘p_sign_posn’] = Integer(1) 1 <br>| [‘n_sign_posn’] = Integer(1) 1 <br>| [‘grouping’] => Array (0) <br>| ( <br>| ) <br>| [‘mon_grouping’] => Array (2) <br>| ( <br>| | [‘0’] = Integer(1) 3 <br>| | [‘1’] = Integer(1) 3 <br>| ) <br>) <br> <br>I don’t know if the following contributed to this success, but I also did the following: <br> <br>sudo apt-get install language-pack-en-base <br> <br>sudo dpkg-reconfigure locales <br> <br>and then rebooted.

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>