mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
ReaderDictionary: add info message about installing dictionaries
Fixes #2816.
This commit is contained in:
committed by
Qingping Hou
parent
fa12f488e8
commit
ed7937f65d
@@ -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 = "<!%[CDATA%[(.-)%]%]>"
|
||||
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
|
||||
|
||||
@@ -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 <code>\/:*?"<>|</code> with an <code>_</code>.
|
||||
|
||||
Reference in New Issue
Block a user