This is a copy of #5950, but for the 0.10 branch.
Unfortually a fallback to "C" locale via std::locale::global does not cover all scenarios with messed up environment locale settings and on Ubuntu 14.01 (with LANG=en_US.UTF-8, LANGUAGE=en_US, LC_* empty) setting LANG=invalid triggers a crash right at the start of bitcoind and bitcoin-qt.
This also affects test_bitcoin and test_bitcoin-qt, which were not guarded at all.
The PR expands the scope of the locale fallback and prevents crashes due to invalid locale settings of bitcoind, bitcoin-qt, test_bitcoin and test_bitcoin-qt.
I used the RPC test test_locale.py to confirm the 0.10 branch is affected by bad locale environment settings in this build, and that this PR does what it should in another build.
The test was not added to this PR, because it executes the Boost tests a few times, which seems too expensive and wasteful.