Modul:usex
Izgled
Dokumentaciju za ovaj modul možete napraviti na stranici Modul:usex/dok
local export = {}
local translit_data = mw.loadData("Module:translations/data")
local has_auto_translit = translit_data[1]
local needs_translit = translit_data[2]
local languages = mw.loadData("Module:languages")
function export.display(frame)
NAMESPACE = mw.title.getCurrentTitle().nsText
local args = frame:getParent().args
local lang = args["lang"] or "und"
local langinfo = languages[lang] or error("The language code \"" .. lang .. "\" is not valid.")
local sc = args["sc"]; if sc == "" then sc = nil end
local noenum = args["noenum"]; if noenum == "" then noenum = nil end
local indent = tonumber(args["indent"]) or 0; if indent < -1 then error("invalid indent") end
local inline = args["inline"]; if inline == "" then inline = nil end
local usex = args[1] or ""; if NAMESPACE ~= "Template" and usex == "" then error("please add a usage example") end
local transliteration = args["tr"] or args["transliteration"] or ""
local translation = args["t"] or args["translation"] or ""
local ref = args["ref"] or ""
local categories = {}
-- auto translit
if transliteration == "" and has_auto_translit[lang] then
local translit_module = require("Module:" .. lang .. "-translit")
transliteration = translit_module.tr(frame:expandTemplate{ title = "delink", args = {usex}})
end
-- add category if transliteration is needed
if transliteration == "" and needs_translit[lang] then
table.insert(categories, langinfo.names[1] .. " terms lacking transliteration")
end
-- add trreq category if translation is unspecified and language is specified and not english
if translation == "" and lang ~= "" and lang ~= "sh" and lang ~= "und" then
table.insert(categories, "Translation requests (" .. langinfo.names[1] .. ")")
translation = "<small>(molimo dodajte srpskohrvatski prijevod)</small>"
end
local result = ""
for key, cat in ipairs(categories) do
result = result .. "[[Category:" .. cat .. "]]"
end
if noenum == true or noenum == "1" then
indent = -1
result = "\n: " .. result
end
local usex_expanded = frame:expandTemplate{ title = "lang", args = {lang, usex, sc = sc }}
-- italicize if script is Latn or lang is unspecified
if langinfo.scripts[2] == nil and langinfo.scripts[1] == "Latn" or lang == "und" then
usex_expanded = "<i>" .. usex_expanded .. "</i>"
end
if inline == true or inline == "1" then
result = result .. usex_expanded .. ref
if transliteration ~= "" then
result = result .. " (" .. transliteration .. ")"
end
if translation ~= "" then
result = result .. " — " .. translation
end
return result
end
result = result .. usex_expanded .. ref
if transliteration ~= "" then
result = result .. "\n" .. string.rep("#", indent + 1) .. ":: " .. transliteration
end
if translation ~= "" then
result = result .. "\n" .. string.rep("#", indent + 1) .. ":: " .. translation
end
return result
end
return export