From 69e6707f9d65aa9253846d2aa96572dcb4240429 Mon Sep 17 00:00:00 2001 From: Jan Holesovsky Date: Fri, 26 Jan 2018 20:28:46 +0100 Subject: lok: Allow whitelisting languages that should be used by LibreOfficeKit. LOK may get way too many languages if there are dictionaries for them installed which blows the pre-init to >2G easily; let's allow limiting that. Also make the preloading of languages work with the internal spell checking dictionaries and thesauri. Change-Id: I77119970030a7386a5cccbe4fdc89b15eab56ef1 Reviewed-on: https://gerrit.libreoffice.org/48720 Tested-by: Jenkins Reviewed-by: Michael Meeks (cherry picked from commit 3a68b21c212c1c2fc7f1d8f4d1abc8990bcd91c0) --- comphelper/source/misc/lok.cxx | 48 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'comphelper') diff --git a/comphelper/source/misc/lok.cxx b/comphelper/source/misc/lok.cxx index 2e8624d1e8d0..589f57b61bce 100644 --- a/comphelper/source/misc/lok.cxx +++ b/comphelper/source/misc/lok.cxx @@ -9,6 +9,8 @@ #include +#include + namespace comphelper { @@ -112,6 +114,52 @@ const LanguageTag& getLanguageTag() return g_aLanguageTag; } +bool isWhitelistedLanguage(const OUString& lang) +{ + if (!isActive()) + return true; + + static bool bInitialized = false; + static std::vector aWhitelist; + if (!bInitialized) + { + const char* pWhitelist = getenv("LOK_WHITELIST_LANGUAGES"); + if (pWhitelist) + { + std::stringstream stream(pWhitelist); + std::string s; + + std::cerr << "Whitelisted languages: "; + while (getline(stream, s, ' ')) { + if (s.length() == 0) + continue; + + std::cerr << s << " "; + aWhitelist.emplace_back(OStringToOUString(s.c_str(), RTL_TEXTENCODING_UTF8)); + } + std::cerr << std::endl; + } + + if (aWhitelist.empty()) + std::cerr << "No language whitelisted, turning off the language support." << std::endl; + + bInitialized = true; + } + + if (aWhitelist.empty()) + return false; + + for (auto& entry : aWhitelist) + { + if (lang.startsWith(entry)) + return true; + if (lang.startsWith(entry.replace('_', '-'))) + return true; + } + + return false; +} + static void (*pStatusIndicatorCallback)(void *data, statusIndicatorCallbackType type, int percent)(nullptr); static void *pStatusIndicatorCallbackData(nullptr); -- cgit v1.2.3