Module:translations
Documentation for this module may be created at Module:translations/documentation
local export = {}
local m_languages = require("Module:languages")
local m_links = require("Module:links")
function export.show(frame)
local function sort_function(a, b)
return a.name < b.name
end
local translations = {}
local title
local args = frame:getParent().args
for k, v in pairs(args) do
if k == 1 then
title = string.gsub(v, "%s+$", "")
elseif type(k) == "string" and type(v) == "string" then
local language = m_languages.get_by_code(k)
-- m_links.full_link{term = word, language = m_languages.get_by_code("rad")} --
-- divide v into pieces in order to be linked --
local to_process = v
local bytext = ""
while #to_process > 0 do
if mw.ustring.match(to_process, "%*[^%*]+%*") then
local pre = mw.ustring.match(to_process, "^([^%*]+)%*")
local pre_len = 0
local translink = mw.ustring.match(to_process, "%*([^%*]+)%*")
if pre then pre_len = mw.ustring.len(pre) end
to_process = mw.ustring.sub(to_process, pre_len + mw.ustring.len(translink) + 2)
translink = m_links.full_link{term = translink, language = language}
bytext = bytext .. pre .. translink
else
bytext = bytext .. to_process
to_process = ""
end
end
table.insert(translations, {name = language.name, display = language.name .. ": " .. bytext})
end
end
if not title then error("the first parameter provided must be a title for the translations box") end
table.sort(translations, sort_function)
local out = '<div class="mw-collapsible mw-collapsed" data-expandtext="{{int:show}}" data-collapsetext="{{int:hide}}" style="padding:0.2em 0.6em 0.2em 0.6em; border-right:1px solid #BEBEBE; border-bottom:1px dotted black; background:#EDEDED">'
out = out .. "'''" .. title .. "'''"
out = out .. '\n<div class="z-index:-1; toccolours mw-collapsible-content" style="border:0;">'
out = out .. '\n{| border="0" width="100%" class="translations"'
out = out .. '\n|-'
out = out .. '\n| bgcolor="beige" valign="top" width="48%" |'
for _, n in ipairs(translations) do out = out .. '\n* ' .. n.display end
out = out .. '\n|}'
out = out .. '\n</div></div>'
return out
end
return export