Provide a single static instance of C++ locale.

We can't use std::locale::global because all streams imbue it by
default and if it's not 'C' (aka std::locale::classic) then we
must imbue all the streams that we don't want localized, and that's
most of them.

Provides error checking for setting the C++ locale from the environment.
This is necessary both because the environment might have an invalid
locale, which would cause an unhandled exception crash.

On windows std::locale("") can't handle some Microsoft-style locale
strings (e.g. Spanish_Spain) so we use boost::locale's gen("") function
to set the locale--though even that can't handle a Microsoft-style
locale string with an appended charset (e.g. Spanish_Spain.1252) and
that's what glibc's setlocale(LC_ALL, NULL) emits.
This commit is contained in:
John Ralls
2019-01-06 09:52:43 -08:00
parent cee97be8d4
commit b4fedff90e
10 changed files with 139 additions and 8 deletions

View File

@@ -64,6 +64,7 @@ extern "C" {
#endif
}
#include "gnc-locale-utils.hpp"
#include <boost/filesystem.hpp>
#include <boost/locale.hpp>
#include <iostream>
@@ -587,9 +588,8 @@ static std::string migrate_gnc_datahome()
gen.add_messages_path(gnc_path_get_datadir());
gen.add_messages_domain(PACKAGE);
// std::locale::global(gen(""));
std::stringstream migration_msg;
migration_msg.imbue(gen(""));
migration_msg.imbue(gnc_get_locale());
/* Step 1: copy directory $HOME/.gnucash to $GNC_DATA_HOME */
auto full_copy = copy_recursive (old_dir, gnc_userdata_home);