mirror of
https://github.com/koreader/koreader.git
synced 2025-12-18 12:02:09 +01:00
'Set typography language' action in Dispatcher (#14465)
This commit is contained in:
@@ -234,6 +234,10 @@ When the book's language tag is not among our presets, no specific features will
|
||||
end
|
||||
return text
|
||||
end,
|
||||
checked_func = function()
|
||||
return self.text_lang_tag == lang_tag
|
||||
end,
|
||||
radio = true,
|
||||
callback = function()
|
||||
-- We use an InfoMessage because the text might be too long for a Notification.
|
||||
-- Use a small timeout (but long enough to read) as this might be bothering.
|
||||
@@ -241,10 +245,7 @@ When the book's language tag is not among our presets, no specific features will
|
||||
text = T(_("Changed language for typography rules to %1."), BD.wrap(lang_name)),
|
||||
timeout = 2,
|
||||
})
|
||||
self.text_lang_tag = lang_tag
|
||||
self.ui.document:setTextMainLang(lang_tag)
|
||||
self.ui:handleEvent(Event:new("TypographyLanguageChanged"))
|
||||
self.ui:handleEvent(Event:new("UpdatePos"))
|
||||
self:onSetTypographyLanguage(lang_tag)
|
||||
end,
|
||||
hold_callback = function(touchmenu_instance)
|
||||
UIManager:show(MultiConfirmBox:new{
|
||||
@@ -268,9 +269,6 @@ When the book's language tag is not among our presets, no specific features will
|
||||
end,
|
||||
})
|
||||
end,
|
||||
checked_func = function()
|
||||
return self.text_lang_tag == lang_tag
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
@@ -456,6 +454,7 @@ These settings will apply to all books with any hyphenation dictionary.
|
||||
return self.hyphenation and not self.hyph_soft_hyphens_only
|
||||
and not self.hyph_force_algorithmic
|
||||
end,
|
||||
radio = true,
|
||||
enabled_func = function()
|
||||
return self.hyphenation
|
||||
end,
|
||||
@@ -493,6 +492,7 @@ These settings will apply to all books with any hyphenation dictionary.
|
||||
-- so have that check even if we reset them above)
|
||||
return self.hyphenation and not self.hyph_soft_hyphens_only and self.hyph_force_algorithmic
|
||||
end,
|
||||
radio = true,
|
||||
enabled_func = function()
|
||||
return self.hyphenation
|
||||
end,
|
||||
@@ -528,6 +528,7 @@ These settings will apply to all books with any hyphenation dictionary.
|
||||
checked_func = function()
|
||||
return self.hyphenation and self.hyph_soft_hyphens_only
|
||||
end,
|
||||
radio = true,
|
||||
enabled_func = function()
|
||||
return self.hyphenation
|
||||
end,
|
||||
@@ -578,6 +579,29 @@ function ReaderTypography:addToMainMenu(menu_items)
|
||||
}
|
||||
end
|
||||
|
||||
function ReaderTypography:onSetTypographyLanguage(lang_tag)
|
||||
if lang_tag == true then -- book language, from Dispatcher
|
||||
lang_tag = self.book_lang_tag
|
||||
or G_reader_settings:readSetting("text_lang_fallback")
|
||||
or G_reader_settings:readSetting("text_lang_default")
|
||||
end
|
||||
if lang_tag then
|
||||
self.text_lang_tag = lang_tag
|
||||
self.ui.document:setTextMainLang(lang_tag)
|
||||
self.ui:handleEvent(Event:new("TypographyLanguageChanged"))
|
||||
self.ui:handleEvent(Event:new("UpdatePos"))
|
||||
end
|
||||
end
|
||||
|
||||
function ReaderTypography.getLangTags() -- for Dispatcher
|
||||
local tags, names = { true }, { _("book language") }
|
||||
for i, v in ipairs(LANGUAGES) do
|
||||
tags[i + 1] = v[1]
|
||||
names[i + 1] = v[4]
|
||||
end
|
||||
return tags, names
|
||||
end
|
||||
|
||||
function ReaderTypography:onToggleFloatingPunctuation(toggle)
|
||||
-- for some reason the toggle value read from history files may stay boolean
|
||||
-- and there seems no more elegant way to convert boolean values to numbers
|
||||
@@ -785,23 +809,20 @@ function ReaderTypography:onPreRenderDocument(config)
|
||||
-- user can see it and switch from and back to it easily
|
||||
table.insert(self.language_submenu, 1, {
|
||||
text = T(_("Book language: %1"), self.book_lang_tag or _("N/A")),
|
||||
callback = function()
|
||||
UIManager:show(InfoMessage:new{
|
||||
text = T(_("Changed language for typography rules to book language: %1."), BD.wrap(self.book_lang_tag)),
|
||||
timeout = 2,
|
||||
})
|
||||
self.text_lang_tag = self.book_lang_tag
|
||||
self.ui.doc_settings:saveSetting("text_lang", self.text_lang_tag)
|
||||
self.ui.document:setTextMainLang(self.text_lang_tag)
|
||||
self.ui:handleEvent(Event:new("TypographyLanguageChanged"))
|
||||
self.ui:handleEvent(Event:new("UpdatePos"))
|
||||
end,
|
||||
enabled_func = function()
|
||||
return self.book_lang_tag ~= nil
|
||||
end,
|
||||
checked_func = function()
|
||||
return self.text_lang_tag == self.book_lang_tag
|
||||
end,
|
||||
radio = true,
|
||||
callback = function()
|
||||
UIManager:show(InfoMessage:new{
|
||||
text = T(_("Changed language for typography rules to book language: %1."), BD.wrap(self.book_lang_tag)),
|
||||
timeout = 2,
|
||||
})
|
||||
self:onSetTypographyLanguage(self.book_lang_tag)
|
||||
end,
|
||||
separator = true,
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user