cache lookup lang

This commit is contained in:
Kovid Goyal 2022-08-29 07:25:35 +05:30
parent 789b79dbd5
commit a3eaabbd93
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -4,6 +4,7 @@
import sys import sys
import textwrap import textwrap
from functools import lru_cache
from qt.core import ( from qt.core import (
QAbstractItemView, QApplication, QCheckBox, QComboBox, QDialog, QDialogButtonBox, QAbstractItemView, QApplication, QCheckBox, QComboBox, QDialog, QDialogButtonBox,
QFormLayout, QHBoxLayout, QIcon, QLabel, QLineEdit, QListWidget, QListWidgetItem, 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): def google_dictionary(word):
ans = f'https://www.google.com/search?q=define:{word}' ans = f'https://www.google.com/search?q=define:{word}'
l = canonicalize_lang(get_lang()) lang = lookup_lang()
if l: if lang:
l = lang_as_iso639_1(l) or l ans += f'#dobc={lang}'
ans += f'#dobc={l}'
return ans return ans