Module:Template:R:IcelandicOnlineDictionary

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

This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

local m_str_utils = require("Module:string utilities")

local codepoint = m_str_utils.codepoint
local ugsub = m_str_utils.gsub
local uri_encode = mw.uri.encode

local export = {}

function export.uri_encode(arg1)
	return uri_encode(
		ugsub(arg1, '[^\0-\127]', function (c)
			local i = codepoint(c)
			if i < 256 then
				return string.char(i)
			else
				return "?"
			end
		end),
		'QUERY'
	)
end

function export.main(frame)
	local args = frame:getParent().args
	local arg1 = args[1] or mw.title.getCurrentTitle().text    -- {{{1|{{PAGENAME}}}}}
	local q1 = export.uri_encode(arg1)
	return (
		'"[http://digicoll.library.wisc.edu/cgi-bin/IcelOnline/IcelOnline.TEId-idx' ..
		'?type=simple&size=First+100&rgn=lemma&q1=' .. q1 .. '&submit=Search' ..
		' ' .. arg1 .. ']" in <i>Icelandic Online Dictionary and Readings</i>.'
	)
end

return export