A modult a Modul:hi/doc lapon tudod dokumentálni

local export = {}

local lang = require("Module:languages").getByCode("hi")
local m_translit = require("Module:hi-translit")
local gsub = mw.ustring.gsub
local sub = mw.ustring.sub

--From [[Module:th]]
function export.new(frame)
	local title = mw.title.getCurrentTitle().text
	local args = frame:getParent().args
	local pos = args[1] or ""
	local def = args[2] or "{{rfdef|lang=hi}}"
	local pos2 = args[3] or (args[4] and "" or false)
	local def2 = args[4] or "{{rfdef|lang=hi}}"
	local pos3 = args[5] or (args[6] and "" or false)
	local def3 = args[6] or "{{rfdef|lang=hi}}"
	local etym = args["e"] or false
	local head = args["head"] or false
	local pron = args["pron"] or false
	local g = args["g"] or false
    local g2 = args["g2"] or false
    local g3 = args["g3"] or false
    local decl = args["decl"] or false
	local conj = args["conj"] or false -- conjugation stuff
    local v = args["v"] or false
    local karna = args["karna"] or false
    local t = args["t"] or false
    local c = args["c"] or args["cat"] or false
    local ref = args["ref"] or false
    local pp = args["pp"] or false --perfect participle

	local result = ""
	
	local function genTitle(text)
		local pos_title = {
			[""] = "Noun", ["n"] = "Noun", ["pn"] = "Proper noun", ["propn"] = "Proper noun", ["pron"] = "Pronoun",
			["v"] = "Verb", ["a"] = "Adjective", ["adj"] = "Adjective", ["adv"] = "Adverb",
			["prep"] = "Preposition", ["postp"] = "Postposition", ["post"] = "Postposition", ["con"] = "Conjunction",
			["part"] = "Particle", ["suf"] = "Suffix", ["pref"] = "Prefix",
			["prov"] = "Proverb", ["id"] = "Idiom", ["ph"] = "Phrase", ["intj"] = "Interjection", ["interj"] = "Interjection",
			["num"] = "Numeral", ["abb"] = "Abbreviation", ["conj"] = "Conjunction",
            ["adj-form"] = "Adjective", ["verb-form"] = "Verb", ["noun-form"] = "Noun",
            ["pp"] = "Perfect participle",
		};
		return pos_title[text] or mw.ustring.upper(sub(text, 1, 1)) .. sub(text, 2, -1)
	end
	
	local function genHead(text)
		local pos_head = {
			[""] = "noun", ["n"] = "noun", ["pn"] = "proper noun", ["propn"] = "proper noun", ["v"] = "verb", ["a"] = "adj", ["adv"] = "adv",
			["postp"] = "post", ["prep"] = "prep", ["conj"] = "con", ["pron"] = "pron",
			["intj"] = "interj", ["pp"] = "perfect participle",
		};
		return pos_head[text] or text
	end
	
	local function other(class, title, args)
		local code = ""
		if args[class] then
			code = code .. "\n\n===" .. title .. "===\n* {{l|hi|" .. args[class] .. "}}"
			
			if args[class .. "2"] then
				code = code .. "\n* {{l|hi|" .. args[class .. "2"] .. "}}"
				
				if args[class .. "3"] then
					code = code .. "\n* {{l|hi|" .. args[class .. "3"] .. "}}"
					
					if args[class .. "4"] then
						code = code .. "\n* {{l|hi|" .. args[class .. "4"] .. "}}"
					end
				end
			end
		end
		return code
	end
	
	-- header
	result = result .. "==Hindi=="
	
	-- Wikipedia
	if args["wp"] then result = result .. "\n{{wikipedia|lang=hi}}" end
	
	-- Alternative forms
	result = result .. other("alt", "Alternative forms", args)
	
	-- Etymology
	if etym then etym = mw.ustring.gsub(etym, "^%<", "From") end
	if etym then result = result .. "\n\n===Etymology===\n" .. etym end
	
	-- Pronunciation
	if pron then
		result = result .. "\n\n===Pronunciation===\n* {{hi-IPA" .. ((pron ~= title and pron ~= "") and ("|" .. gsub(pron, ",", "|")) or "") .. "}}"
	else
		result = result .. "\n\n===Pronunciation===\n* {{hi-IPA}}"
	end
	result = result .. "\n\n===" .. genTitle(pos) .. "===\n{{hi-" .. genHead(pos) .. (head and ("|head=" .. head) or "") .. (g and ("|g=" .. g) or "") .. (t and ("|" .. t) or "") .. (pp and ("|" .. pp) or "") .. "}}\n\n# " .. def
    
    -- Morphology
    if decl then result = result .. "\n\n====Declension====\n{{hi-" .. genHead(pos) .. "-" .. ((decl ~= title and decl ~= "") and (gsub(decl, ",", "|")) or "") .. "}}" end
    if conj then result = result .. "\n\n====Conjugation====\n{{hi-conj" .. (v and ("-v") or "") .. (karna and ("-karna") or "") .. "|" .. (conj or "") .. "}}" end
	
	-- Other
	result = result .. other("syn", "=Synonyms=", args)
	result = result .. other("ant", "=Antonyms=", args)
	result = result .. other("der", "=Derived terms=", args)
	result = result .. other("also", "=See also=", args)
	
	-- Actual Entry
	if pos2 then
		result = result .. "\n\n===" .. genTitle(pos2) .. "===\n{{hi-" .. genHead(pos2) .. (head and ("|head=" .. head) or "") .. (g2 and ("|g=" .. g2) or "") .. "}}\n\n# " .. def2
	end
	
	if pos3 then
		result = result .. "\n\n===" .. genTitle(pos3) .. "===\n{{hi-" .. genHead(pos3) .. (head and ("|head=" .. head) or "")  .. (g3 and ("|g=" .. g3) or "") .. "}}\n\n# " .. def3
	end
    
    -- categories and references
    if ref and ref ~= "" then
    	result = result .. "\n\n===References===\n* {{R:hi:McGregor" .. (ref and ("|" .. ref) or "") .."}}"
    elseif ref == "" then
    	result = result .. "\n\n===References===\n* {{R:hi:McGregor}}"
    end
    
    if c then
    	result = result .. "\n\n{{topics|hi" .. ((c ~= title and c ~= "") and ("|" .. gsub(c, ",", "|")) or "") .. "}}"
    end
	
	return result
end


function export.usex(frame) --from [[Module:ne-utilities]] by [[User:Wyang]]
	local args = frame:getParent().args
	local text = {}
	local example = args[1] or error("Example has not been specified. Please pass parameter 1 to the module invocation.")
	local translation = args[2] or ""
	local lit = args["lit"] or ""
	local m_links = require("Module:links").remove_links
	
	local translit = m_translit.tr(m_links(example), "hi", "Deva")
	local formatted = gsub(example, "'''(.-)'''", "<span style=\"background&#45;color:#FEF8EA\"><b>%1</b></span>")

	if mw.ustring.len(example) > 30 or args["noinline"] then
		table.insert(text, (frame:expandTemplate{ title = 'ux', args = { 'hi', formatted, tr = translit, translation, lit = lit} }))
	else
		table.insert(text, (frame:expandTemplate{ title = 'uxi', args = { 'hi', formatted, tr = translit, translation, lit = lit} }))
	end
	
	return table.concat(text)
end

function export.hi_format(text)
	text = ('<span lang="hi" class="Deva">[[%s]]</span>'):format(text)
	return text
end

function export.wordify(text)
	local words, translits = {}, {}
	for word in mw.text.gsplit(text, ",") do
		table.insert(words, export.hi_format(word))
		table.insert(translits, m_translit.tr(word, "hi", "Deva"))
	end
	text = table.concat(words, ", ") .. "<br><span style=\"color:#888\">" ..
		table.concat(translits, ", ") .. "</span>"
	return text
end

return export