Jump to content

Մոդուլ:usex

Վիքիբառարան-ից

Documentation for this module may be created at Մոդուլ:usex/doc

local translit_data = mw.loadData("Module:translations/data")
local needs_translit = translit_data[2]
local export = {}

function export.display(frame)
	local args = frame:getParent().args
	
	if (frame.args["compat"] or "") ~= "" then
		args[3] = args["t"] or args["translation"] or args[2]
		args[2] = args["example"] or args[1]
		args[1] = args["lang"]
	end
	
	local lang = args[1]; if lang == "" then lang = nil end
	local sc = args["sc"]; if sc == "" then sc = nil end
	
	if (frame.args["compat"] or "") ~= "" or mw.title.getCurrentTitle().nsText == "Կաղապար" then
		lang = lang or "und"
	end
	
	lang = require("Module:languages").getByCode(lang) or error("The language code \"" .. lang .. "\" is not valid.")
	sc = (sc and (require("Module:scripts").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")) or nil)
	
	local usex = args[2]; if usex == "" then usex = nil end
	local transliteration = args["tr"] or args["transliteration"]; if transliteration == "" then transliteration = nil end
	local translation = args[3]; if translation == "" then translation = nil end
	local noenum = args["noenum"]; if noenum == "" then noenum = nil end
	local inline = args["inline"]; if inline == "" then inline = nil end
	local ref = args["ref"]; if ref == "" then ref = nil end
	
	local categories = {}
	
	if not sc then
		sc = require("Module:scripts").findBestScript(usex, lang)
	end
	
	-- temporary category for japanese
	if transliteration and (string.find(transliteration, "<br/>") or string.find(transliteration, "<br>")) then
		table.insert(categories, "usex with multiple transliterations")
	end
	
	-- auto translit
	if usex and not transliteration then
		transliteration = lang:transliterate(require("Module:links").remove_links(usex), sc)
	end
	
	-- add category if transliteration is needed
	if not transliteration and needs_translit[lang] then
		table.insert(categories, lang:getCanonicalName() .. " terms needing transliteration")
	end
	
	local result = ""
	
	if noenum then
		result = "\n: " .. result
	end
	
	if inline then
		result = result .. usex .. (ref or "")
		
		if transliteration then
			result = result .. " ― <i>" .. transliteration .. "</i>"
		end
		
		if translation then
			result = result .. " ― " .. translation
		end
		
		for key, cat in ipairs(categories) do
			result = result .. "[[Category:" .. cat .. "]]"
		end
		
		return result
	end	

	if mw.title.getCurrentTitle().fullText ~= 'Կաղապար:usex' then
		for key, cat in ipairs(categories) do
			result = result .. "[[Category:" .. cat .. "]]"
		end
	end
	
	if mw.title.getCurrentTitle().nsText == 'Կաղապար' then
		usex = 'օրինակ'
	end
	
	result = result .. usex .. (ref or "")
	
	if transliteration or translation then
		result = result .. "<dl>"
		
		if transliteration then
			if lang:getCode() == "ja" then
				result = result .. "<dd>" .. require("Module:links").remove_links(transliteration) .. "</dd>"
			else
				result = result .. "<dd><i>" .. require("Module:links").remove_links(transliteration) .. "</i></dd>"
			end
		end
	
		if translation then
			result = result .. "<dd>" .. translation .. "</dd>"
		end
		
		result = result .. "</dl>"
	end
	
	return result
end

return export