diff --git a/include/loot/api.h b/include/loot/api.h index a9a348ad..2dbd9a17 100644 --- a/include/loot/api.h +++ b/include/loot/api.h @@ -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 diff --git a/src/api/api.cpp b/src/api/api.cpp index 3617514f..de057393 100644 --- a/src/api/api.cpp +++ b/src/api/api.cpp @@ -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 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."); diff --git a/src/tests/api/interface/main.cpp b/src/tests/api/interface/main.cpp index 0f4e93ca..46a0f084 100644 --- a/src/tests/api/interface/main.cpp +++ b/src/tests/api/interface/main.cpp @@ -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);