Module:rhymes
Appearance
Documentation for this module may be created at Module:rhymes/doc
local export = {}
function export.show_nav(frame)
-- Gather parameters
local args = frame:getParent().args
local lang = args[1] or (mw.title.getCurrentTitle().nsText == "Template" and "und") or error("Language code has not been specified. Please pass parameter 1 to the template.")
lang = require("Module:languages").getByCode(lang) or error("The language code \"" .. lang .. "\" is not valid.")
local parts = {}
local i = 2
while args[i] do
local part = args[i]; if part == "" then part = nil end
table.insert(parts, part)
i = i + 1
end
-- Create steps
local steps = {"» [[Wiktionary:Rhymes|Rhymes]]", "» [[Rhymes:" .. lang:getCanonicalName() .. "|" .. lang:getCanonicalName() .. "]]"}
local categories = {}
if #parts > 0 then
local last = parts[#parts]
parts[#parts] = nil
local prefix = ""
for i, part in ipairs(parts) do
prefix = prefix .. part
parts[i] = prefix
end
for _, part in ipairs(parts) do
table.insert(steps, "» [[Rhymes:" .. lang:getCanonicalName() .. "/" .. part .. "-|-" .. part .. "-]]")
end
if last == "-" then
table.insert(steps, "» [[Rhymes:" .. lang:getCanonicalName() .. "/" .. prefix .. "|-" .. prefix .. "]]")
table.insert(categories, "[[Category:" .. lang:getCanonicalName() .. " rhymes" .. (prefix == "" and "" or "/" .. prefix .. "-") .. "| ]]")
elseif mw.title.getCurrentTitle().text == lang:getCanonicalName() .. "/" .. prefix .. last .. "-" then
table.insert(steps, "» [[Rhymes:" .. lang:getCanonicalName() .. "/" .. prefix .. last .. "-|-" .. prefix .. last .. "-]]")
table.insert(categories, "[[Category:" .. lang:getCanonicalName() .. " rhymes/" .. prefix .. last .. "-|-]]")
else
table.insert(steps, "» [[Rhymes:" .. lang:getCanonicalName() .. "/" .. prefix .. last .. "|-" .. prefix .. last .. "]]")
table.insert(categories, "[[Category:" .. lang:getCanonicalName() .. " rhymes" .. (prefix == "" and "" or "/" .. prefix .. "-") .. "|" .. last .. "]]")
end
elseif lang ~= "und" then
table.insert(categories, "[[Category:" .. lang:getCanonicalName() .. " rhymes| ]]")
end
return table.concat(steps, " ") .. table.concat(categories)
end
return export