summaryrefslogtreecommitdiff
path: root/comphelper/source/misc
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@collabora.com>2018-01-26 20:28:46 +0100
committerMichael Meeks <michael.meeks@collabora.com>2018-01-27 11:04:32 +0100
commit3a68b21c212c1c2fc7f1d8f4d1abc8990bcd91c0 (patch)
tree9c3fc0e1e217ae9c453ed961e2e1cecb17a3b9a7 /comphelper/source/misc
parent079775c0d52a49cef5e22790149ad97747c1e940 (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>
Diffstat (limited to 'comphelper/source/misc')
-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);