Modulo:frazo

De Wikivortaro

Dokumentizo por ica modulo povas kreesar ye Modulo:frazo/dokumentado

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

function export.format_usex(lang, sc, usex, translation, transliteration, noenum, inline, ref, quote)
	local categories = {}
	
	if not sc then
		sc = require("Module:skripti").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
	
	-- tr=- means omit transliteration altogether
	if transliteration == "-" then
		transliteration = nil
	else
		-- Try to auto-transliterate
		if not transliteration and usex then
			transliteration = lang:transliterate(require("Module:ligili").remove_links(usex), sc)
		end
		
		-- If there is still no transliteration, then add a cleanup category
		if not transliteration and needs_translit[lang] then
			table.insert(categories, lang:getCanonicalName() .. " terms needing transliteration")
		end
	end
	
	-- add trreq category if translation is unspecified and language is specified and not english
	if not translation and lang:getCode() ~= "io" and lang:getCode() ~= "und" then
		table.insert(categories, "Traduko-demandi (" .. lang:getCanonicalName() .. ")")
		translation = "<small>(voluntez adjuntar Idala tradukuro ad ica " .. (quote and "citajo" or "uzexemplo") .. ")</small>"
	end
	
	local result = ""
	
	if noenum then
		result = "\n: " .. result
	end
	
	if not usex then
		usex = "<small>(please add the primary text of this " .. (quote and "quote" or "usage example") .. ")</small>"
		-- TODO: Trigger some kind of error here
	else
		if mw.ustring.find(usex, "[[", nil, true) then
			usex = require("Module:ligili").language_link({term = usex, lang = lang}, false)
		end
		
		usex = require("Module:skripto-utilaji").tag_text(usex, lang, sc, nil)
		
		-- italicize if script is Latn or lang is unspecified
		-- TODO: This should be done through tag_text
		if (not quote) and (sc:getCode():find("Latn", nil, true) or sc:getCode() == "Latinx" or lang:getCode() == "und") then
			usex = "<i>" .. usex .. "</i>"
		end
	end
	
	if inline then
		result = result .. usex .. "&lrm;" .. (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 .. "[[Kategorio:" .. cat .. "]]"
		end
		
		return result
	end	
	
	if mw.title.getCurrentTitle().fullText ~= 'Shablono:frazo' then
		for key, cat in ipairs(categories) do
			result = result .. "[[Kategorio:" .. cat .. "]]"
		end
	end
	
	result = result .. usex .. "&lrm;" .. (ref or "")
	
	if transliteration or translation then
		result = result .. "<dl>"
		
		if transliteration then
			if lang:getCode() == "ja" then
				result = result .. "<dd>" .. transliteration .. "</dd>"
			else
				result = result .. "<dd><i>" .. transliteration .. "</i></dd>"
			end
		end
		
		if translation then
			result = result .. "<dd>" .. translation .. "</dd>"
		end
		
		result = result .. "</dl>"
	end
	
	return result
end

return export