Add an API function that initialises the global locale

It should be called whenever the client changes the global locale.
This commit is contained in:
Oliver Hamlet
2017-02-12 21:58:58 +00:00
parent b6f48d5291
commit dbfeea47c1
3 changed files with 15 additions and 9 deletions
+9
View File
@@ -92,6 +92,15 @@ LOOT_API bool IsCompatible(const unsigned int major,
*************************************************************************/
/**@{*/
/**
* Initialise the current global locale using the given ID.
*
* This sets the global locale up so that the library's UTF-8 support can
* function.
* @param locale A locale ID.
*/
LOOT_API void InitialiseLocale(const std::string& id);
/**
* @brief Initialise a new game handle.
* @details Creates a handle for a game, which is then used by all
+5 -9
View File
@@ -61,10 +61,6 @@ LOOT_API void SetLoggingVerbosity(LogVerbosity verbosity) {
}
LOOT_API void SetLogFile(const std::string& path) {
// Set the locale to get UTF-8 conversions working correctly.
std::locale::global(boost::locale::generator().generate(""));
boost::filesystem::path::imbue(std::locale());
boost::log::add_file_log(
boost::log::keywords::file_name = path,
boost::log::keywords::auto_flush = true,
@@ -85,14 +81,14 @@ LOOT_API bool IsCompatible(const unsigned int versionMajor, const unsigned int v
return versionMinor == loot::LootVersion::minor;
}
LOOT_API void InitialiseLocale(const std::string& id) {
std::locale::global(boost::locale::generator().generate(id));
boost::filesystem::path::imbue(std::locale());
}
LOOT_API std::shared_ptr<GameInterface> CreateGameHandle(const GameType game,
const std::string& gamePath,
const std::string& gameLocalPath) {
// Set the locale to get UTF-8 conversions working correctly.
std::locale::global(boost::locale::generator().generate(""));
boost::filesystem::path::imbue(std::locale());
// Check for valid paths.
const std::string resolvedGamePath = ResolvePath(gamePath);
if (!gamePath.empty() && !fs::is_directory(resolvedGamePath))
throw std::invalid_argument("Given game path \"" + gamePath + "\" does not resolve to a valid directory.");
+1
View File
@@ -36,6 +36,7 @@ int main(int argc, char **argv) {
//Set the locale to get encoding conversions working correctly.
std::locale::global(boost::locale::generator().generate(""));
boost::filesystem::path::imbue(std::locale());
loot::InitialiseLocale("");
//Disable logging or else stdout will get overrun.
boost::log::core::get()->set_logging_enabled(false);