[RTL UI] Bidi-wrap filenames, paths, urls, metadata

bidi.lua:
- Revert "Alias everything to Bidi.nowrap() when in LTR UI,
  as using LTR isolates seems uneeded when already LTR" (part
  of a628714f) which was a wrong assumption: we need proper
  wrappers for all things paths. Enhance some of these wrappers.
- Fix GetText RTL wrapping which was losing empty lines and
  trailing \n.

- Wrap all paths, directories, filenames in the code with
  these wrappers.
- Wrap all book metadata (title, authors...) with BD.auto(),
  as it helps fixing some edge cases (like open/close quotation
  marks which are not considered as bracket types by FriBiDi).
  (Needed some minor logic changes in CoverBrowser.)

- Tweak hyphenation menu text
- Update forgotten SortWidget for UI mirroring
- KoptConfig: update "justification" index for RTL re-ordering,
  following the recent addition of the page_gap_height option.
This commit is contained in:
poire-z
2020-01-04 01:18:51 +01:00
parent a31abf79de
commit 0599c440cc
50 changed files with 378 additions and 182 deletions

View File

@@ -1,3 +1,4 @@
local BD = require("ui/bidi")
local ConfirmBox = require("ui/widget/confirmbox")
local DataStorage = require("datastorage")
local Device = require("device")
@@ -233,7 +234,7 @@ function ReaderDictionary:addToMainMenu(menu_items)
text = T(_([[
If you'd like to change the order in which dictionaries are queried (and their results displayed), you can:
- move all dictionary directories out of %1.
- move them back there, one by one, in the order you want them to be used.]]), self.data_dir)
- move them back there, one by one, in the order you want them to be used.]]), BD.dirpath(self.data_dir))
})
end,
},
@@ -928,7 +929,7 @@ function ReaderDictionary:downloadDictionary(dict, download_location, continue)
logger.dbg("file downloaded to", download_location)
else
UIManager:show(InfoMessage:new{
text = _("Could not save file to:\n") .. download_location,
text = _("Could not save file to:\n") .. BD.filepath(download_location),
--timeout = 3,
})
return false

View File

@@ -1,3 +1,4 @@
local BD = require("ui/bidi")
local CenterContainer = require("ui/widget/container/centercontainer")
local ConfirmBox = require("ui/widget/confirmbox")
local Device = require("device")
@@ -397,7 +398,7 @@ a { color: black; }
f:write("</body></html>\n")
f:close()
UIManager:show(ConfirmBox:new{
text = T(_("Document created as:\n%1\n\nWould you like to read it now?"), fonts_test_path),
text = T(_("Document created as:\n%1\n\nWould you like to read it now?"), BD.filepath(fonts_test_path)),
ok_callback = function()
UIManager:scheduleIn(1.0, function()
self.ui:switchDocument(fonts_test_path)

View File

@@ -1490,7 +1490,7 @@ function ReaderGesture:gestureAction(action, ges)
local current_network = NetworkMgr:getCurrentNetwork()
-- this method is only available for some implementations
if current_network and current_network.ssid then
info_text = T(_("Already connected to network %1."), current_network.ssid)
info_text = T(_("Already connected to network %1."), BD.wrap(current_network.ssid))
else
info_text = _("Already connected.")
end

View File

@@ -791,7 +791,7 @@ function ReaderHighlight:viewSelectionHTML(debug_view)
if css_files then
for i=1, #css_files do
local button = {
text = T(_("View %1"), css_files[i]),
text = T(_("View %1"), BD.filepath(css_files[i])),
callback = function()
local css_text = self.ui.document:getDocumentFileContent(css_files[i])
local cssviewer

View File

@@ -1,3 +1,4 @@
local BD = require("ui/bidi")
local Device = require("device")
local Event = require("ui/event")
local InfoMessage = require("ui/widget/infomessage")
@@ -25,13 +26,16 @@ function ReaderHyphenation:init()
table.insert(self.hyph_table, {
text_func = function()
local limits_text = _("language defaults")
if G_reader_settings:readSetting("hyph_left_hyphen_min")
or G_reader_settings:readSetting("hyph_right_hyphen_min") then
limits_text = T("%1 - %2", G_reader_settings:readSetting("hyph_left_hyphen_min"),
-- Note: with our callback, we either get hyph_left_hyphen_min and
-- hyph_right_hyphen_min both nil, or both defined.
if G_reader_settings:readSetting("hyph_left_hyphen_min") or
G_reader_settings:readSetting("hyph_right_hyphen_min") then
-- @translators to RTL language translators: %1/left is the min length of the start of a hyphenated word, %2/right is the min length of the end of a hyphenated word (note that there is yet no support for hyphenation with RTL languages, so this will mostly apply to LTR documents)
return T(_("Left/right minimal sizes: %1 - %2"),
G_reader_settings:readSetting("hyph_left_hyphen_min"),
G_reader_settings:readSetting("hyph_right_hyphen_min"))
end
return T(_("Left/right minimal sizes: %1"), limits_text)
return _("Left/right minimal sizes: language defaults")
end,
callback = function()
local DoubleSpinWidget = require("/ui/widget/doublespinwidget")
@@ -120,7 +124,7 @@ These settings will apply to all books with any hyphenation dictionary.
self.hyph_alg = v.filename
self.ui.doc_settings:saveSetting("hyph_alg", self.hyph_alg)
UIManager:show(InfoMessage:new{
text = T(_("Changed hyphenation to %1."), v.name),
text = T(_("Changed hyphenation to %1."), BD.wrap(v.name)),
})
self.ui.document:setHyphDictionary(v.filename)
-- Apply hyphenation sides limits
@@ -137,7 +141,7 @@ These settings will apply to all books with any hyphenation dictionary.
-- one is set, no fallback will ever be used - if a fallback one
-- is set, no default is wanted; so when we set one below, we
-- remove the other).
text = T( _("Would you like %1 to be used as the default (★) or fallback (<28>) hyphenation language?\n\nDefault will always take precedence while fallback will only be used if the language of the book can't be automatically determined."), v.name),
text = T( _("Would you like %1 to be used as the default (★) or fallback (<28>) hyphenation language?\n\nDefault will always take precedence while fallback will only be used if the language of the book can't be automatically determined."), BD.wrap(v.name)),
choice1_text = _("Default"),
choice1_callback = function()
G_reader_settings:saveSetting("hyph_alg_default", v.filename)

View File

@@ -534,7 +534,7 @@ function ReaderLink:onGotoLink(link, neglect_current_location, allow_footnote_po
display_filename = display_filename .. anchor
end
UIManager:show(ConfirmBox:new{
text = T(_("Would you like to read this local document?\n\n%1\n"), display_filename),
text = T(_("Would you like to read this local document?\n\n%1\n"), BD.filepath(display_filename)),
ok_callback = function()
UIManager:scheduleIn(0.1, function()
self.ui:switchDocument(linked_filename)
@@ -543,7 +543,7 @@ function ReaderLink:onGotoLink(link, neglect_current_location, allow_footnote_po
})
else
UIManager:show(InfoMessage:new{
text = T(_("Link to unsupported local file:\n%1"), link_url),
text = T(_("Link to unsupported local file:\n%1"), BD.url(link_url)),
})
end
return true
@@ -551,7 +551,7 @@ function ReaderLink:onGotoLink(link, neglect_current_location, allow_footnote_po
-- Not supported
UIManager:show(InfoMessage:new{
text = T(_("Invalid or external link:\n%1"), link_url),
text = T(_("Invalid or external link:\n%1"), BD.url(link_url)),
-- no timeout to allow user to type that link in his web browser
})
-- don't propagate, user will notice and tap elsewhere if he wants to change page
@@ -658,7 +658,7 @@ function ReaderLink:onGoToExternalLink(link_url)
-- No external link handler
return false
end
text = T(_("External link:\n\n%1"), link_url)
text = T(_("External link:\n\n%1"), BD.url(link_url))
end
-- Add all alternative handlers buttons

View File

@@ -228,7 +228,7 @@ function ReaderMenu:setUpdateItemTable()
return _("Open previous document")
end
local path, file_name = util.splitFilePathName(previous_file) -- luacheck: no unused
return T(_("Previous: %1"), file_name)
return T(_("Previous: %1"), BD.filename(file_name))
end,
enabled_func = function()
return self:getPreviousFile() ~= nil
@@ -239,7 +239,7 @@ function ReaderMenu:setUpdateItemTable()
hold_callback = function()
local previous_file = self:getPreviousFile()
UIManager:show(ConfirmBox:new{
text = T(_("Would you like to open the previous document: %1?"), previous_file),
text = T(_("Would you like to open the previous document: %1?"), BD.filepath(previous_file)),
ok_text = _("OK"),
ok_callback = function()
self.ui:switchDocument(previous_file)

View File

@@ -1,3 +1,4 @@
local BD = require("ui/bidi")
local BookStatusWidget = require("ui/widget/bookstatuswidget")
local ButtonDialogTitle = require("ui/widget/buttondialogtitle")
local Device = require("device")
@@ -181,7 +182,7 @@ function ReaderStatus:deleteFile(file, text_end_book)
message_end_book = "You've reached the end of the document.\n"
end
UIManager:show(ConfirmBox:new{
text = T(_("%1Are you sure that you want to delete this file?\n%2\nIf you delete a file, it is permanently lost."), message_end_book, file),
text = T(_("%1Are you sure that you want to delete this file?\n%2\nIf you delete a file, it is permanently lost."), message_end_book, BD.filepath(file)),
ok_text = _("Delete"),
ok_callback = function()
local FileManager = require("apps/filemanager/filemanager")

View File

@@ -1,3 +1,4 @@
local BD = require("ui/bidi")
local Blitbuffer = require("ffi/blitbuffer")
local ButtonTable = require("ui/widget/buttontable")
local CenterContainer = require("ui/widget/container/centercontainer")
@@ -498,7 +499,7 @@ You can enable individual tweaks on this book with a tap, or view more details a
table.insert(item_table, {
title = title,
id = file, -- keep ".css" in id, to distinguish between koreader/user tweaks
description = T(_("User style tweak at %1"), filepath),
description = T(_("User style tweak at %1"), BD.filepath(filepath)),
priority = 10, -- give user tweaks a higher priority
css_path = filepath,
})

View File

@@ -1,3 +1,4 @@
local BD = require("ui/bidi")
local ConfirmBox = require("ui/widget/confirmbox")
local Event = require("ui/event")
local InfoMessage = require("ui/widget/infomessage")
@@ -252,7 +253,7 @@ function ReaderTypeset:genStyleSheetMenu()
text_func = function()
local text = _("Obsolete")
if obsoleted_css[self.css] then
text = T(_("Obsolete (%1)"), obsoleted_css[self.css])
text = T(_("Obsolete (%1)"), BD.filename(obsoleted_css[self.css]))
end
if obsoleted_css[G_reader_settings:readSetting("copt_css")] then
text = text .. ""
@@ -450,7 +451,7 @@ end
function ReaderTypeset:makeDefaultStyleSheet(css, text, touchmenu_instance)
UIManager:show(ConfirmBox:new{
text = T( _("Set default style to %1?"), text),
text = T( _("Set default style to %1?"), BD.filename(text)),
ok_callback = function()
G_reader_settings:saveSetting("copt_css", css)
if touchmenu_instance then touchmenu_instance:updateItems() end

View File

@@ -1,3 +1,4 @@
local BD = require("ui/bidi")
local ButtonDialogTitle = require("ui/widget/buttondialogtitle")
local ConfirmBox = require("ui/widget/confirmbox")
local DataStorage = require("datastorage")
@@ -175,7 +176,7 @@ function ReaderWikipedia:addToMainMenu(menu_items)
if not default_dir then default_dir = require("apps/filemanager/filemanagerutil").getDefaultDir() end
local dialog
dialog = ButtonDialogTitle:new{
title = T(_("Current Wikipedia 'Save as EPUB' directory:\n\n%1\n"), default_dir),
title = T(_("Current Wikipedia 'Save as EPUB' directory:\n\n%1\n"), BD.dirpath(default_dir)),
buttons = {
{
{
@@ -220,7 +221,7 @@ function ReaderWikipedia:addToMainMenu(menu_items)
onConfirm = function(path)
G_reader_settings:saveSetting("wikipedia_save_dir", path)
UIManager:show(InfoMessage:new{
text = T(_("Wikipedia 'Save as EPUB' directory set to:\n%1"), path),
text = T(_("Wikipedia 'Save as EPUB' directory set to:\n%1"), BD.dirpath(path)),
})
end
}
@@ -257,7 +258,7 @@ Where do you want them saved?]])
end
G_reader_settings:saveSetting("wikipedia_save_dir", wikipedia_dir)
UIManager:show(InfoMessage:new{
text = T(_("Wikipedia 'Save as EPUB' directory set to:\n%1"), wikipedia_dir),
text = T(_("Wikipedia 'Save as EPUB' directory set to:\n%1"), BD.dirpath(wikipedia_dir)),
})
end,
cancel_text = _("Select directory"),