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,
|
||||
})
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ local Notification = require("ui/widget/notification")
|
||||
local ReaderDictionary = require("apps/reader/modules/readerdictionary")
|
||||
local ReaderFooter = require("apps/reader/modules/readerfooter")
|
||||
local ReaderHighlight = require("apps/reader/modules/readerhighlight")
|
||||
local ReaderTypography = require("apps/reader/modules/readertypography")
|
||||
local ReaderZooming = require("apps/reader/modules/readerzooming")
|
||||
local Screen = Device.screen
|
||||
local UIManager = require("ui/uimanager")
|
||||
@@ -218,6 +219,7 @@ local settingsList = {
|
||||
export_annotations = {category="none", event="ExportAnnotations", title=_("Export annotations"), reader=true},
|
||||
|
||||
-- Reflowable documents
|
||||
set_typography_lang = {category="string", event="SetTypographyLanguage", title=_("Set typography language"), args_func=ReaderTypography.getLangTags, rolling=true, separator=true},
|
||||
set_font = {category="string", event="SetFont", title=_("Font face"), rolling=true, args_func=require("fontlist").getFontArgFunc,},
|
||||
increase_font = {category="incrementalnumber", event="IncreaseFontSize", min=0.5, max=255, step=0.5, title=_("Increase font size"), rolling=true},
|
||||
decrease_font = {category="incrementalnumber", event="DecreaseFontSize", min=0.5, max=255, step=0.5, title=_("Decrease font size"), rolling=true},
|
||||
@@ -462,6 +464,8 @@ local dispatcher_menu_order = {
|
||||
"export_annotations",
|
||||
|
||||
-- Reflowable documents
|
||||
"set_typography_lang",
|
||||
----
|
||||
"set_font",
|
||||
"increase_font",
|
||||
"decrease_font",
|
||||
@@ -941,6 +945,7 @@ function Dispatcher:_addItem(caller, menu, location, settings, section)
|
||||
end
|
||||
end
|
||||
end,
|
||||
radio = true,
|
||||
callback = function()
|
||||
setValue(k, settingsList[k].args[i])
|
||||
end,
|
||||
|
||||
Reference in New Issue
Block a user