summaryrefslogtreecommitdiff
path: root/comphelper
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@collabora.com>2018-01-26 20:28:46 +0100
committerAndras Timar <andras.timar@collabora.com>2018-03-25 17:38:26 +0200
commit69e6707f9d65aa9253846d2aa96572dcb4240429 (patch)
tree9772ad5ac14238c7ad0599147a7dba70b3587aaa /comphelper
parent7907f2c478c4669962ecb60b85c3d007f4b07deb (diff)
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 <ci@libreoffice.org> Reviewed-by: Michael Meeks <michael.meeks@collabora.com> (cherry picked from commit 3a68b21c212c1c2fc7f1d8f4d1abc8990bcd91c0)
Diffstat (limited to 'comphelper')
-rw-r--r--comphelper/source/misc/lok.cxx48
1 files changed, 48 insertions, 0 deletions
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 <comphelper/lok.hxx>
+#include <iostream>
+
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<OUString> 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);