diff --git a/frontend/apps/reader/modules/readerdictionary.lua b/frontend/apps/reader/modules/readerdictionary.lua
index 3c262ea33..d046c2a52 100644
--- a/frontend/apps/reader/modules/readerdictionary.lua
+++ b/frontend/apps/reader/modules/readerdictionary.lua
@@ -43,6 +43,15 @@ function ReaderDictionary:onLookupWord(word, box, highlight)
return true
end
+local function dictDirsEmpty(dict_dirs)
+ for _, dict_dir in ipairs(dict_dirs) do
+ if not util.isEmptyDir(dict_dir) then
+ return false
+ end
+ end
+ return true
+end
+
local function tidyMarkup(results)
local cdata_tag = ""
local format_escape = "&[29Ib%+]{(.-)}"
@@ -135,6 +144,19 @@ function ReaderDictionary:stardictLookup(word, box)
if lfs.attributes(dict_ext, "mode") == "directory" then
table.insert(dict_dirs, dict_ext)
end
+ -- early exit if no dictionaries
+ if dictDirsEmpty(dict_dirs) then
+ final_results = {
+ {
+ dict = "",
+ word = word,
+ definition = _([[No dictionaries installed. Please search for "Dictionary support" in the KOReader Wiki to get more information about installing new dictionaries.]]),
+ }
+ }
+ self:onLookupDone()
+ self:showDict(word, final_results, box)
+ return
+ end
for _, dict_dir in ipairs(dict_dirs) do
local results_str = nil
if Device:isAndroid() then
diff --git a/frontend/util.lua b/frontend/util.lua
index 457ee3775..9f1968c5f 100644
--- a/frontend/util.lua
+++ b/frontend/util.lua
@@ -283,6 +283,18 @@ function util.getFilesystemType(path)
return type
end
+--- Checks if directory is empty.
+---- @string path
+---- @treturn bool
+function util.isEmptyDir(path)
+ for filename in require("lfs").dir(path) do
+ if filename ~= '.' and filename ~= '..' then
+ return false
+ end
+ end
+ return true
+end
+
--- Replaces characters that are invalid filenames.
--
-- Replaces the characters \/:*?"<>|
with an _
.