-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Translator: translate current page #10438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
frontend/ui/translator.lua
Outdated
if NetworkMgr:willRerunWhenOnline(function() self:showTranslation(text, target_lang, source_lang, from_highlight, page, index) end) then | ||
if NetworkMgr:willRerunWhenOnline(function() | ||
self:showTranslation(text, target_lang, source_lang, from_highlight, page, index, full_page) end) then | ||
return | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure it's more readable than before :)
May be go a bit more proper:
if NetworkMgr:willRerunWhenOnline(function()
self:showTranslation(text, target_lang, source_lang, from_highlight, page, index, full_page)
end) then
return
end
frontend/ui/translator.lua
Outdated
if not full_page then | ||
table.insert(output, "▣ " .. table.concat(source, " ")) | ||
end | ||
text_main = (full_page and "" or "● ") .. table.concat(translated, " ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(When naming this new parameter "full_page", did you think about translating the current full page - or showing the result translation full page ? I would have named it "no_alt_translation" or "simple_translation" as you're just ignoring all the other translations/definitions. But may be this ambivalent "full_page", because it is ambivalent, is fine.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this snippet would read better if you kept the 2 ways separate, rather than (full_page and "" or "● ") ..
:
if full_page then
text_main = table.concat(translated, " ")
else
table.insert(output, "▣ " .. table.concat(source, " "))
text_main = "● " .. table.concat(translated, " ")
end
frontend/ui/translator.lua
Outdated
function Translator:onTranslateCurrentPage() | ||
local ui = require("apps/reader/readerui").instance | ||
if not ui or not ui.document then return end | ||
local x0, y0, x1, y1, page | ||
if ui.rolling then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels all this "reader" business should better be done in your added:
function ReaderHighlight:onTranslateCurrentPage()
Translator:onTranslateCurrentPage()
end
It is still ReaderHighlight:onTranslateCurrentPage that will always be called, isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, it must be done in ReaderHighlight.
@@ -202,6 +202,7 @@ local order = { | |||
"wikipedia_history", | |||
"wikipedia_settings", | |||
"----------------------------", | |||
"translate_page", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will add a 11th item in that menu (10th for me with Vocabulary builder disabled), so making it 2 pages :/
No real better idea. In the 2nd menu with a page icon? so-so.
May be the dict & wiki lookup history should be moved into their respecting ... settings, or be in the own submenu?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
12 (incl. calibre search).
Maybe move dict, wiki and translation settings into Settings submenu?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, might be a good idea, now that "Translation" has one "action" item in there.
-- main menu Search | ||
menu_items.search_settings = { -- submenu with Dict, Wiki, Translation settings | ||
text = _("Settings"), | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be this one should better be in readerdictionary, which is the one that brings into it the most subitems and the first in that search menu? (ReaderHighlight feels a bit unrelated).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about wordings inconsistency Dictionary lookup history
vs Wikipedia history
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dunno when/where this difference comes from :/ @Frenzie will tell us if/how we should fix that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know where it came from, but I think "Dictionary history" might be a bit ambiguous? So in that sense I'd prefer Wikipedia lookup history
if you feel it lacks balance, but I think it's fine as is.
@@ -340,6 +342,8 @@ local dispatcher_menu_order = { | |||
"book_description", | |||
"book_cover", | |||
|
|||
"translate_page", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(OK about having it here, can't find a better place in the Reader> actions menu.)
frontend/ui/translator.lua
Outdated
@@ -526,6 +557,7 @@ function Translator:_showTranslation(text, target_lang, source_lang, from_highli | |||
end | |||
local output = {} | |||
local text_main = "" | |||
local not_full_page = not full_page |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels ugly and prone to typo :)
And it means "detailed".
So, may be name it everywhere "detailed", and if the default should be true:
if detailed == nil then detailed = true end
and pass false
when you don't want it.
frontend/ui/translator.lua
Outdated
end) | ||
end | ||
|
||
function Translator:_showTranslation(text, target_lang, source_lang, from_highlight, page, index) | ||
function Translator:_showTranslation(text, target_lang, source_lang, from_highlight, page, index, translate_page) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some thoughts (not insisting too much, but just in case you'd agree :):
translate_page
still feels a bit odd.
Translator can be seen as some utility tool, and shouldn't really be that linked to the idea of translating a book page or a fragment of a book content. It could be used to translate a Book description, or some Wikipedia result content.
So, ideally, the params shouldn't indicate what's the source (with some inner logic to decide what's expected as the result), but directly what's expected. So, "detailed" vs "simple".
We do pass from_highlight/page/index, so yes, there is a bit of outer context, but that's just for adding buttons.
(Isn't from_highlight a synonym of translate_fragment, ie. it's not there when you translate a page? Or can we don't have it even with fragments?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"detailed" vs "simple"
Yes, I thought about these wordings, but translate_page mode also gets source lang from the book and shows bigger window.
Isn't from_highlight a synonym of translate_fragment, ie. it's not there when you translate a page? Or can we don't have it even with fragments?
We can translate_fragment from the pen_button in DictQuickLookup,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but translate_page mode also gets source lang from the book
Shouldn't it be readerhighlight that should get the source lang from the self.ui it knows and pass it to Translator:showTranslation(), instead of passing nil?
and shows bigger window
This could be implied when using "simple", or passed as another parameter (ie. large_window).
Fix translation for books without "language" in properties (it is "", Translator expects nil). Regression after #10438.
Looks like "[x] Auto detect source language" has no longer the intended effect. |
Sounds like Google autodetect got worse? ;-P |
Available via the menu and with a gesture.
Forces book language (if available) as a source language.
Shows main translation only, without source text, alternative translations and definitions.
Just a page to read.
Closes #10199.
This change is