Skip to content

Commit

Permalink
split dict into 2 groups
Browse files Browse the repository at this point in the history
  • Loading branch information
cdhigh committed Dec 24, 2024
1 parent 8289036 commit 9fbfdd6
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 13 deletions.
4 changes: 2 additions & 2 deletions application/lib/calibre/web/feeds/news.py
Original file line number Diff line number Diff line change
Expand Up @@ -2074,9 +2074,10 @@ def translate_titles(self, feeds):
translator = HtmlTranslator(self.translator, self.simultaneous_downloads)
position = self.translator.get('position', 'below')
texts = []

#内嵌函数
def _addTextItem(obj, attr):
return texts.append({'text': getattr(obj, attr, None), 'obj': obj, 'attr': attr})
texts.append({'text': getattr(obj, attr, None), 'obj': obj, 'attr': attr})

for feed in feeds:
_addTextItem(feed, 'title')
Expand All @@ -2101,7 +2102,6 @@ def _addTextItem(obj, attr):
setattr(obj, attr, item['translated'])

#调用在线TTS服务平台,将html转为语音
#每个音频片段都会调用一次callback(audioDict, title, feed_index, article_index)
def audiofy_html(self, soup, title, job_info):
from ebook_tts import HtmlAudiolator
audiolator = HtmlAudiolator(self.tts)
Expand Down
1 change: 1 addition & 0 deletions application/lib/dictionary/babylon/babylon_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def getBglDictList():

class BabylonDict:
name = "babylon"
mode = "offline"
#词典列表,键为词典缩写,值为词典描述
databases = getBglDictList()

Expand Down
1 change: 1 addition & 0 deletions application/lib/dictionary/dict_cc.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def n_results(self):

class DictCc:
name = "dict.cc"
mode = "online"
#词典列表,键为词典缩写,值为词典描述
databases = {"en": "English",
"de": "German",
Expand Down
1 change: 1 addition & 0 deletions application/lib/dictionary/dict_cn.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

class DictCn:
name = "dict.cn"
mode = "online"
#词典列表,键为词典缩写,值为词典描述
databases = {"english": "English-Chinese Translation Dictionary"}

Expand Down
1 change: 1 addition & 0 deletions application/lib/dictionary/dict_org.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

class DictOrg:
name = "dict.org"
mode = "online"
#词典列表,键为词典缩写,值为词典描述
databases = {"!": "First match",
"gcide": "The Collaborative International Dictionary of English v.0.48",
Expand Down
1 change: 1 addition & 0 deletions application/lib/dictionary/lingvo/lingvo_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def getDslDictList():

class LingvoDict:
name = "lingvo"
mode = "offline"
#词典列表,键为词典缩写,值为词典描述
databases = getDslDictList()

Expand Down
1 change: 1 addition & 0 deletions application/lib/dictionary/mdict/mdict.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def getMDictFileList():

class MDict:
name = "mdict"
mode = "offline"
#词典列表,键为词典缩写,值为词典描述
databases = getMDictFileList()

Expand Down
1 change: 1 addition & 0 deletions application/lib/dictionary/merriam_webster.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

class MerriamWebster:
name = "webster's"
mode = "online"
#词典列表,键为词典缩写,值为词典描述
databases = {"english": "Webster's New International Dictionary"}

Expand Down
1 change: 1 addition & 0 deletions application/lib/dictionary/oxford_learners.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

class OxfordLearners:
name = "oxford's"
mode = "online"
#词典列表,键为词典缩写,值为词典描述
databases = {"learner": "Advanced Learner's Dictionary",
"advanced": "Advanced American Dictionary"}
Expand Down
1 change: 1 addition & 0 deletions application/lib/dictionary/stardict/stardict.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def getStarDictList():

class StarDict:
name = "stardict"
mode = "offline"
#词典列表,键为词典缩写,值为词典描述
databases = getStarDictList()

Expand Down
2 changes: 1 addition & 1 deletion application/lib/urlopener.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __init__(self, *, host=None, timeout=60, headers=None, file_stub=None, user_
self.addheaders[0] = ('User-Agent', user_agent)

self.fs = file_stub #FsDictStub
self.session = requests.session()
self.session = requests.Session()
if self._proxies:
self.session.proxies.update(self._proxies)
self.prevRespRef = None #对Response实例的一个弱引用
Expand Down
28 changes: 20 additions & 8 deletions application/static/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -1716,16 +1716,28 @@ function SendTestEmail() {

//根据词典引擎列表 g_dictEngines 和 当前配置 g_dictParams 填充下拉框
function PopulateDictFields() {
for (var idx = 0; idx < 3; idx++) {
var cfg = g_dictParams[idx];
var engineSel = $('#dict_engine' + idx);
for (let idx = 0; idx < 3; idx++) {
const cfg = g_dictParams[idx];
const engineSel = $('#dict_engine' + idx);
engineSel.empty();
var engineName = cfg.engine;
for (var name in g_dictEngines) {
var selected = (engineName == name) ? 'selected="selected"' : '';
var txt = `<option value="${name}" ${selected}>${name}</option>`;
engineSel.append($(txt));
const engineName = cfg.engine;
const groupedEngines = {'Online': [], 'Offline': []};
for (const name in g_dictEngines) { //分组词典引擎
const mode = g_dictEngines[name].mode;
groupedEngines[(mode === 'online') ? 'Online' : 'Offline'].push(name);
}

//添加选项到engineSel
['Online', 'Offline'].forEach((group) => {
if (groupedEngines[group].length) {
const grp = $('<optgroup>', { label: group });
groupedEngines[group].forEach((name) => {
const selected = (engineName === name) ? 'selected' : '';
grp.append($(`<option value="${name}" ${selected}>${name}</option>`));
});
engineSel.append(grp);
}
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion application/view/adv.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ def AdvDict(user: KeUser):
if hasattr(dic, 'refresh'):
dic.refresh()

engines = {name: {'databases': klass.databases} for name,klass in all_dict_engines.items()}
engines = {name: {'databases': klass.databases, 'mode': klass.mode} for name,klass in all_dict_engines.items()}
return adv_render_template('adv_dict.html', 'dictionary', user=user, engines=engines,
dictParams=dictParams, tips='', langMap=LangMap())

Expand Down
2 changes: 1 addition & 1 deletion application/view/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def ReaderDictRoute(user: KeUser, userDir: str):
if hasattr(dic, 'refresh'):
dic.refresh()

engines = {name: {'databases': klass.databases} for name,klass in all_dict_engines.items()}
engines = {name: {'databases': klass.databases, 'mode': klass.mode} for name,klass in all_dict_engines.items()}
return render_template('word_lookup.html', user=user, engines=engines, tips='', langMap=LangMap())

#Api查词
Expand Down

0 comments on commit 9fbfdd6

Please sign in to comment.