From a3eaabbd93dde4763ea5c5603d74ab64a269b6f0 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 29 Aug 2022 07:25:35 +0530 Subject: [PATCH] cache lookup lang --- src/calibre/gui2/viewer/lookup.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/calibre/gui2/viewer/lookup.py b/src/calibre/gui2/viewer/lookup.py index fd1a560cd2..d88daf0759 100644 --- a/src/calibre/gui2/viewer/lookup.py +++ b/src/calibre/gui2/viewer/lookup.py @@ -4,6 +4,7 @@ import sys import textwrap +from functools import lru_cache from qt.core import ( QAbstractItemView, QApplication, QCheckBox, QComboBox, QDialog, QDialogButtonBox, QFormLayout, QHBoxLayout, QIcon, QLabel, QLineEdit, QListWidget, QListWidgetItem, @@ -23,12 +24,19 @@ from calibre.utils.webengine import ( ) +@lru_cache +def lookup_lang(): + ans = canonicalize_lang(get_lang()) + if ans: + ans = lang_as_iso639_1(ans) or ans + return ans + + def google_dictionary(word): ans = f'https://www.google.com/search?q=define:{word}' - l = canonicalize_lang(get_lang()) - if l: - l = lang_as_iso639_1(l) or l - ans += f'#dobc={l}' + lang = lookup_lang() + if lang: + ans += f'#dobc={lang}' return ans