Dokumentacja dla tego modułu może zostać utworzona pod nazwą Moduł:słowo dnia/opis

local data = {}
data[ 'hu' ] = require 'Module:słowo dnia/dane/węgierski'
data[ 'lt' ] = require 'Module:słowo dnia/dane/litewski'
data[ 'ro' ] = require 'Module:słowo dnia/dane/rumuński'
data[ 'tr' ] = require 'Module:słowo dnia/dane/turecki'
data[ 'uk' ] = require 'Module:słowo dnia/dane/ukraiński'

local p = {}

local function splitByPlainSeparator(str, sep, max)
	-- http://lua-users.org/wiki/SplitJoin
    local z = #sep; sep = '^.-'..sep:gsub('[$%%()*+%-.?%[%]^]', '%%%0')
    local t,n,p, q,r = {},1,1, str:find(sep)
    while q and n~=max do
        t[n],n,p = str:sub(q,r-z),n+1,r+1
        q,r = str:find(sep,p)
    end
    t[n] = str:sub(p)
    return t
end

local get_lang = function( name , lang )
	local title = mw.title.new(name, 0)
	local out = {
		title = '',
		content = ''
	}
	if title ~= nil and title.exists then
		out.title = name
		local cnt = title:getContent()
		local tab = splitByPlainSeparator(cnt,' ({{język ' .. mw.language.fetchLanguageNames('pl')[lang] .. '}}) ==\n',100)
		if tab[2] ~= nil then
			cnt = tab[2]
		else
			cnt = ''
		end
		tab = splitByPlainSeparator(cnt,'\n== ',100)
		if tab[2] ~= nil then
			cnt = tab[1]
		end
		
		local escapedName = name:gsub('[$%%()*+%-.?%[%]^]', '%%%0')
		cnt = cnt:gsub('{{translit|' .. lang .. '}}', '{{translit|' .. lang .. '|' .. name .. '}}')
		cnt = cnt:gsub("%[%[" .. escapedName .. "%]%]([%a]*)", "<b>[[" .. name .. "]]%1</b>")
		cnt = cnt:gsub("%[%[" .. escapedName .. "|([^%]]*)%]%]([%a]*)", "<b>[[" .. name .. "|%1%2]]</b>")
		out.content = cnt
	end
	return out
end

p.generate = function( frame )
	local lang = frame.args[ 1 ]
	local what = frame.args[ 2 ]
	
	out = get_lang( data[ lang ][ 'aktualne' ], lang )
	if out.content == '' then
		out = get_lang( data[ lang ][ 'poprzednie' ], lang )
	end
	if out.content == '' then
		out = get_lang( data[ lang ][ 'rezerwa' ], lang )
	end
	
	if what == 'title' then
		return out.title
	elseif what == 'link' then
		return '[[' .. out.title .. '#' .. lang .. '|' .. out.title .. ']]'
	else
		return frame:preprocess(out.content)
	end
end

return p