mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
E-book viewer: Lookup word in Google dictionary: Fix meanings of some words not being shown in the user's preferred language. Fixes #1985855 [default definition service sometimes translates instead of defining](https://bugs.launchpad.net/calibre/+bug/1985855)
This commit is contained in:
parent
cfe219018d
commit
789b79dbd5
@ -13,19 +13,30 @@ from qt.webengine import (
|
|||||||
QWebEnginePage, QWebEngineProfile, QWebEngineScript, QWebEngineView
|
QWebEnginePage, QWebEngineProfile, QWebEngineScript, QWebEngineView
|
||||||
)
|
)
|
||||||
|
|
||||||
from gettext import pgettext
|
|
||||||
from calibre import prints, random_user_agent
|
from calibre import prints, random_user_agent
|
||||||
from calibre.gui2 import error_dialog
|
from calibre.gui2 import error_dialog
|
||||||
from calibre.gui2.viewer.web_view import apply_font_settings, vprefs
|
from calibre.gui2.viewer.web_view import apply_font_settings, vprefs
|
||||||
from calibre.gui2.widgets2 import Dialog
|
from calibre.gui2.widgets2 import Dialog
|
||||||
|
from calibre.utils.localization import canonicalize_lang, get_lang, lang_as_iso639_1
|
||||||
from calibre.utils.webengine import (
|
from calibre.utils.webengine import (
|
||||||
create_script, insert_scripts, secure_webengine, setup_profile
|
create_script, insert_scripts, secure_webengine, setup_profile
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
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}'
|
||||||
|
return ans
|
||||||
|
|
||||||
|
|
||||||
vprefs.defaults['lookup_locations'] = [
|
vprefs.defaults['lookup_locations'] = [
|
||||||
{
|
{
|
||||||
'name': 'Google dictionary',
|
'name': 'Google dictionary',
|
||||||
'url': 'https://www.google.com/search?q=define:{word}',
|
'url': 'https://www.google.com/search?q=define:{word}',
|
||||||
|
'special_processor': google_dictionary,
|
||||||
'langs': [],
|
'langs': [],
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -359,6 +370,12 @@ class Lookup(QWidget):
|
|||||||
if idx > -1:
|
if idx > -1:
|
||||||
return self.source_box.itemData(idx)['url']
|
return self.source_box.itemData(idx)['url']
|
||||||
|
|
||||||
|
@property
|
||||||
|
def special_processor(self):
|
||||||
|
idx = self.source_box.currentIndex()
|
||||||
|
if idx > -1:
|
||||||
|
return self.source_box.itemData(idx).get('special_processor')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def query_is_up_to_date(self):
|
def query_is_up_to_date(self):
|
||||||
query = self.selected_text or self.current_query
|
query = self.selected_text or self.current_query
|
||||||
@ -377,8 +394,12 @@ class Lookup(QWidget):
|
|||||||
if not self.is_visible or not query:
|
if not self.is_visible or not query:
|
||||||
return
|
return
|
||||||
self.current_source = self.url_template
|
self.current_source = self.url_template
|
||||||
|
sp = self.special_processor
|
||||||
|
if sp is None:
|
||||||
url = self.current_source.format(word=query)
|
url = self.current_source.format(word=query)
|
||||||
pgettext('The meaning of a word, intended to be added to a google web search to lookup word meanings', 'meaning')
|
else:
|
||||||
|
url = sp(query)
|
||||||
|
|
||||||
self.view.load(QUrl(url))
|
self.view.load(QUrl(url))
|
||||||
self.current_query = query
|
self.current_query = query
|
||||||
self.update_refresh_button_status()
|
self.update_refresh_button_status()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user