Module:RQ:be:s

From Wiktionary, the free dictionary
Jump to navigation Jump to search

See Template:RQ:be:s


-- 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.org/wiki/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.org/wiki/Template:RQ:Dickens_Dombey_and_Son
books["Домбі і сын"] = {
    args = {
        author     = "w:Charles Dickens",
        translator = "anonymous",
        year       = "1938",
        origyear   = "1848",
        original   = "[[s:Dombey_and_Son_(1848)|Dombey and Son]]",
        title      = "s:be:Домбі і сын",
        location   = "w:Minsk",
        publisher  = "[[w:be:Беларусь_(выдавецтва)|ДВБ]]",
    },
    urlprefix = "https://be.wikisource.org/wiki/Старонка:Домбі_і_сын.pdf/",
    pagelist  = "7=3"
}

books["Pan Tadeusz (1859)"] = {
    args = {
        author     = "w:Vincent Dunin-Marcinkievič",
        year       = "1859",
        origyear   = "1834",
        original   = "[[s:pl:Pan_Tadeusz_(wyd._1834)|Pan Tadeusz]]",
        by         = "w:Adam Mickiewicz",
        title      = "[[s:be:Pan Tadeusz (1859)|Pan Tadeusz]]",
        location   = "w:Wilno",
        publisher  = "Drukarnia A. Syrkina",
    },
    urlprefix = "https://be.wikisource.org/wiki/Старонка:Pan_Tadeusz_(1859).pdf/",
}

-- Also see https://en.wiktionary.org/wiki/Template:RQ:Twain_Prince_and_the_Pauper
books["Прынц і жабрак (1940)"] = {
    args = {
        author     = "w:Mark Twain",
        translator = "w:Janka Maŭr",
        year       = "1940",
        origyear   = "1882",
        original   = "s:The Prince and the Pauper",
        title      = "[[s:be:Прынц і жабрак (1940)|Прынц і жабрак]]",
        location   = "w:Minsk",
        publisher  = "[[w:be:Беларусь_(выдавецтва)|ДВБ]]",
    },
    urlprefix = "https://be.wikisource.org/wiki/Старонка:Прынц_і_жабрак_(1940).pdf/",
    pagelist  = "7=3"
}

-- Also see https://en.wiktionary.org/wiki/Template:RQ:Stevenson_Treasure_Island
books["Востраў скарбаў"] = {
    args = {
        author     = "w:Robert Louis Stevenson",
        translator = "anonymous",
        year       = "1938",
        origyear   = "1883",
        original   = "[[s:Treasure_Island_(1883)|Treasure Island]]",
        title      = "s:be:Востраў скарбаў",
        location   = "w:Minsk",
        publisher  = "[[w:be:Беларусь_(выдавецтва)|ДВБ]]",
    },
    urlprefix = "https://be.wikisource.org/wiki/Старонка:Востраў_скарбаў.pdf/",
}

-- Also see https://en.wiktionary.org/wiki/Template:RQ:Cooper_Last_of_the_Mohicans
books["Апошні з магікан (1940)"] = {
    args = {
        author     = "w:James Fenimore Cooper",
        translator = "anonymous",
        year       = "1940",
        origyear   = "1826",
        original   = "s:The Last of the Mohicans",
        title      = "[[s:be:Апошні_з_магікан_(1940)|Апошні з магікан]]",
        location   = "w:Minsk",
        publisher  = "[[w:be:Беларусь_(выдавецтва)|ДВБ]]",
    },
    urlprefix = "https://be.wikisource.org/wiki/Старонка:Апошні_з_магікан.pdf/",
}

-- Also see https://en.wiktionary.org/wiki/Template:RQ:Scott_Ivanhoe
books["Айвенго (1934)"] = {
    args = {
        author     = "w:Walter Scott",
        translator = "Іван Гарбуз",
        year       = "1934",
        origyear   = "1820",
        original   = "[[s:Ivanhoe_(1820)|Ivanhoe]]",
        title      = "[[s:be:Айвенго_(1934)|Айвенго]]",
        location   = "w:Minsk",
        publisher  = "[[w:be:Беларусь_(выдавецтва)|ДВБ]]",
    },
    urlprefix = "https://be.wikisource.org/wiki/Старонка:Айвенго_(1934).pdf/",
    pagelist  = "7=5"
}

books["Прыгоды ўдалага ваякі Швэйка (1931—1932)/1"] = {
    args = {
        author     = "w:Jaroslav Hašek",
        translator = "w:be:Міхась Зарэцкі",
        year       = "1931",
        origyear   = "1921",
        origlang   = "cs",
        original   = "s:cs:Osudy dobrého vojáka Švejka za světové války",
        title      = "[[s:be:Прыгоды_ўдалага_ваякі_Швэйка_(1931—1932)/1|У тыле]]",
        series     = "[[s:be:Прыгоды_ўдалага_ваякі_Швэйка_(1931—1932)|Прыгоды ўдалага ваякі Швэйка]]",
        seriesvolume = 1,
        location   = "w:Minsk",
        publisher  = "[[w:be:Беларусь_(выдавецтва)|ДВБ]]",
    },
    urlprefix = "https://be.wikisource.org/wiki/Старонка:Прыгоды_ўдалага_ваякі_Швэйка_(1931—1932)._Частка_1.pdf/",
    pagelist  = "2=3"
}

-- Parse the Wikisource's pagelist data. See
--   https://en.wikisource.org/wiki/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[args.title]
    if not book_info and args.year then
        book_info = books[args.title .. " (" .. tostring(args.year) .. ")"]
    end
    if book_info then
        for k, v in pairs(book_info.args) do
            args[k] = 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 parent_args = frame:getParent().args
	local params = {
		[1] = {alias_of = "title"},
		[2] = {alias_of = "text"},
		[3] = {alias_of = "t"},
        ["title"] = {required = true},
        ["text"] = {required = true},
        ["t"] = {},
		["passage"] = {alias_of = "text"},
		["translation"] = {alias_of = "t"},
	}
	local args, xargs = require("Module:parameters").process(parent_args, params, true)
    for k, v in pairs(xargs) do
        if type(k) == "number" then
           error("Unexpected positional argument " .. k .. "=" .. v)
        end
        args[k] = v
    end

    export.insert_bibliographic_data(args)
    args.lang = args.lang or "be"
    return frame:expandTemplate {title = "quote-book", args = args}
end

return export