-- This module is intended to simplify creating quotations for the old
-- public domain texts available on Belarusian Wikisource. Supports the
-- original Belarusian books, Belarusian translations of English books
-- and, potentially, English translations of Belarusian books.
--
-- Similar to https://en.wiktionary.orghttps://dictious.com/en/Template:Q
-- it maintains a small list of a few notable books to automatically
-- fill in the bibliographic information.
local export = {}
local books = {}
-- Also see https://en.wiktionary.orghttps://dictious.com/en/Template:RQ:Dickens_Dombey_and_Son
books = {
args = {
author = "w:Charles Dickens",
translator = "anonymous",
year = "1938",
origyear = "1848",
original = "]",
title = "s:be:Домбі і сын",
location = "w:Minsk",
publisher = "]",
},
urlprefix = "https://be.wikisource.orghttps://dictious.com/en/Старонка:Домбі_і_сын.pdf/",
pagelist = "7=3"
}
books = {
args = {
author = "w:Vincent Dunin-Marcinkievič",
year = "1859",
origyear = "1834",
original = "]",
by = "w:Adam Mickiewicz",
title = "]",
location = "w:Wilno",
publisher = "Drukarnia A. Syrkina",
},
urlprefix = "https://be.wikisource.orghttps://dictious.com/en/Старонка:Pan_Tadeusz_(1859).pdf/",
}
-- Also see https://en.wiktionary.orghttps://dictious.com/en/Template:RQ:Twain_Prince_and_the_Pauper
books = {
args = {
author = "w:Mark Twain",
translator = "w:Janka Maŭr",
year = "1940",
origyear = "1882",
original = "s:The Prince and the Pauper",
title = "]",
location = "w:Minsk",
publisher = "]",
},
urlprefix = "https://be.wikisource.orghttps://dictious.com/en/Старонка:Прынц_і_жабрак_(1940).pdf/",
pagelist = "7=3"
}
-- Also see https://en.wiktionary.orghttps://dictious.com/en/Template:RQ:Stevenson_Treasure_Island
books = {
args = {
author = "w:Robert Louis Stevenson",
translator = "anonymous",
year = "1938",
origyear = "1883",
original = "]",
title = "s:be:Востраў скарбаў",
location = "w:Minsk",
publisher = "]",
},
urlprefix = "https://be.wikisource.orghttps://dictious.com/en/Старонка:Востраў_скарбаў.pdf/",
}
-- Parse the Wikisource's pagelist data. See
-- https://en.wikisource.orghttps://dictious.com/en/Help:Page_numbers#Page_numbers_in_the_Index_namespace
local function pageurl(page, urlprefix, pagelist)
page = tonumber(page)
local urlpage = page
if pagelist then
pagelist:gsub("(%d+)=(%d+)", function (n1, n2)
n1 = tonumber(n1)
n2 = tonumber(n2)
if n2 <= page then
urlpage = page - n2 + n1
end
end)
end
return urlprefix .. tostring(urlpage)
end
function export.insert_bibliographic_data(args)
local book_info = books
if not book_info and args.year then
book_info = books
end
if book_info then
for k, v in pairs(book_info.args) do
args = v
end
if args.page then
args.pageurl = pageurl(args.page, book_info.urlprefix, book_info.pagelist)
end
end
return args
end
function export.show(frame)
local args = {}
local subst = { = "title", = "text", = "t", passage = "text", translation = "t" }
local function parse_args(args, frame_args)
for k, v in pairs(frame_args) do
local idx = tonumber(k)
if idx and (idx < 1 or idx > 3) then
error("Other than 'title', 'text' and 't', all parameters must be named")
end
args or k] = v
end
end
parse_args(args, frame.args)
parse_args(args, frame:getParent().args)
export.insert_bibliographic_data(args)
args.lang = args.lang or "be"
if not args.title or not args.text then
error("Title and text parameters are required")
end
return frame:expandTemplate { title = "quote-book", args = args }
end
return export