Module:Homophones
local export = {}
local m_links = require("Module:links")
function export.show(frame)
local args = frame:getParent().args
local lang = args["lang"]; if lang == "" then lang = nil end
if not lang then
lang = "en"
end
lang = require("Module:languages").getByCode(lang) or error("The language code \"" .. lang .. "\" is not valid.")
local text = ""
local terms = {} -- because args is unmodifiable
--make the term empty string if only the alternate text exists
for name, parameter in pairs(args) do
local regex = mw.ustring.match(tostring(name),"^alt%d+$")
if regex then
local index = tonumber((name:gsub("alt", "")))
if not args[index] then
terms[index] = ""
end
end
end
--copy all unnamed parameters to terms
for i, param in ipairs(args) do
terms[i] = param
end
--main process
local comma = false
local count = 0
for i, parameter in ipairs(terms) do
count = count + 1
if comma then
text = text .. ", "
else
comma = true
end
local alt = args["alt" .. tostring(i)]
local tr = args["tr" .. tostring(i)]
if parameter == "" then
text = text .. alt
else
text = text .. m_links.full_link({lang = lang, term = parameter, alt = alt, tr = tr})
end
end
--return process
if count > 1 then --add an "s" to "Homophone" if there is more than one term
return "Homophones: " .. text
elseif count == 1 then --no "s" if there is only one term
return "Homophone: " .. text
end
--if there is no term at all, return default text if namespace is Template
if mw.title.getCurrentTitle().nsText == "Template" then
return "Homophone: [[term#Scots|term]]"
end
--if this line is parsed, there are no terms at all and the namespace is not Template
error("Please provide at least one homophone.")
end
return export
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.