wsd/FileServer.cpp | 30 ++++++++++++++++++++++++++---- wsd/LOOLWSD.cpp | 7 +++++++ wsd/LOOLWSD.hpp | 2 ++ 3 files changed, 35 insertions(+), 4 deletions(-)
New commits: commit c2aef686012c4130553a0d36f260b12615408126 Author: Henry Castro <hcas...@collabora.com> AuthorDate: Sun Feb 10 15:25:37 2019 -0400 Commit: Henry Castro <hcas...@collabora.com> CommitDate: Tue Mar 5 19:40:58 2019 -0400 wsd: add boost::locale generation and caching Change-Id: I75009a87038632ceaddb29094d340b6d9066d5ef diff --git a/wsd/FileServer.cpp b/wsd/FileServer.cpp index 409a9c540..b82becbf1 100644 --- a/wsd/FileServer.cpp +++ b/wsd/FileServer.cpp @@ -38,6 +38,9 @@ #include <Poco/StreamCopier.h> #include <Poco/StringTokenizer.h> #include <Poco/URI.h> +#include <boost/locale.hpp> +#include <boost/locale/gnu_gettext.hpp> +#include <boost/exception/all.hpp> #include "Auth.hpp" #include <Common.hpp> @@ -426,6 +429,18 @@ void FileServerRequestHandler::handleRequest(const HTTPRequest& request, Poco::M sendError(404, request, socket, "404 - file not found!", "There seems to be a problem locating"); } + catch (const boost::exception& exc) + { + LOG_WRN("FileServerRequestHandler: " << boost::diagnostic_information(exc)); + sendError(404, request, socket, "404 - file not found!", + "There seems to be a localization problem"); + } + catch (const std::exception& exc) + { + LOG_WRN("FileServerRequestHandler: " << exc.what()); + sendError(404, request, socket, "404 - file not found!", + "Internal error"); + } } void FileServerRequestHandler::sendError(int errorCode, const Poco::Net::HTTPRequest& request, @@ -683,11 +698,19 @@ void FileServerRequestHandler::preprocessFile(const HTTPRequest& request, Poco:: documentSigningDiv = "<div id=\"document-signing-bar\"></div>"; } - std::string lang; - std::locale locale; + std::string lang("en"); std::ostringstream ostr; std::istringstream istr(preprocess); + auto pos = std::find_if(params.begin(), params.end(), + [](const std::pair<std::string, std::string>& it) { return it.first == "lang"; }); + if (pos != params.end()) + { + lang = pos->second; + } + + std::locale locale(LOOLWSD::Generator(lang + ".utf8")); + parse(locale, istr, ostr, [&](const std::string& var) { bool result = true; if (var == "ACCESS_TOKEN") @@ -977,8 +1000,7 @@ void FileServerRequestHandler::parse(const std::locale& locale, std::istringstre { if (state == ParseState::L10n) { - LOG_INF(locale.name()); - //ostr << '\'' << boost::locale::gettext(varL10n.str().c_str(), locale) << '\''; + ostr << '\'' << boost::locale::gettext(varL10n.str().c_str(), locale) << '\''; state = ParseState::None; } else ostr << token; diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp index b135fd6bf..1f0e4dc0a 100644 --- a/wsd/LOOLWSD.cpp +++ b/wsd/LOOLWSD.cpp @@ -694,6 +694,7 @@ unsigned LOOLWSD::MaxConnections; unsigned LOOLWSD::MaxDocuments; std::string LOOLWSD::OverrideWatermark; std::set<const Poco::Util::AbstractConfiguration*> LOOLWSD::PluginConfigurations; +boost::locale::generator LOOLWSD::Generator; static std::string UnitTestLibrary; @@ -1012,6 +1013,12 @@ void LOOLWSD::initialize(Application& self) ChildRoot = getPathFromConfig("child_root_path"); ServerName = config().getString("server_name"); + Generator.locale_cache_enabled(true); + Generator.add_messages_domain("loolwsd"); + Generator.characters(boost::locale::char_facet); + Generator.categories(boost::locale::message_facet); + Generator.add_messages_path(config().getString("application.dir", "./") + "locale"); + FileServerRoot = getPathFromConfig("file_server_root_path"); NumPreSpawnedChildren = getConfigValue<int>(conf, "num_prespawn_children", 1); if (NumPreSpawnedChildren < 1) diff --git a/wsd/LOOLWSD.hpp b/wsd/LOOLWSD.hpp index f4c2db405..73571c9f0 100644 --- a/wsd/LOOLWSD.hpp +++ b/wsd/LOOLWSD.hpp @@ -21,6 +21,7 @@ #include <Poco/Util/AbstractConfiguration.h> #include <Poco/Util/OptionSet.h> #include <Poco/Util/ServerApplication.h> +#include <boost/locale.hpp> #include "Util.hpp" @@ -72,6 +73,7 @@ public: static unsigned MaxDocuments; static std::string OverrideWatermark; static std::set<const Poco::Util::AbstractConfiguration*> PluginConfigurations; + static boost::locale::generator Generator; static std::vector<int> getKitPids(); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits