Documentația acestui modul poate fi creată la Modul:languages/doc
-- Modul pentru crearea listei de traduceri a unui cuvânt în alte limbi
local languages = mw.loadData("Module:languages/data");
local p = {};
local function trimstr(s)
return (s:gsub("^%s*(.-)%s*$", "%1"));
end
local function formatLang(code, name, index, extention)
local result = '';
local margin = '';
result = result .. "* ]";
if index ~= nil and index ~= "" then
local indexes = {
= "восстановленный язык",
= "limbă artificială",
= "реконструированный язык",
= "limbă fictivă",
= "limbă moartă"
}
local title = indexes or '';
if title ~= '' then
title = " title='" .. title .. "'";
end
result = result .. "<sup style='color:#66C033'" .. title .. ">" .. index .. "</sup>";
margin = ';margin-left: -5px';
end
if code ~= nil and code ~= "" then
result = result .. "<sub style='color:#33C066" .. margin .. "'>" .. code .. "</sub>";
end
if extention ~= nil and extention ~= "" then
result = result .. " " .. extention;
end
return result;
end
function p.list(frame)
local result = "";
local names = {};
local nnames = {};
local key = "";
local cnt = 0;
local demo = frame.args;
if demo ~= nil and demo ~= "" then
for code,v in pairs(languages) do
key = v;
if v ~= nil and v ~= "" then
key = key .. v;
end
table.insert(nnames, key);
names = { code = v, name = v, index = v, extention = v, value = code};
cnt = cnt +1;
end;
else
for code,value in pairs(frame:getParent().args) do
if type(code)=='string' then
local trimmed = trimstr(code);
local v = trimstr(value);
local l = languages;
if l ~= nil and l ~= "" and v ~= nil and v ~= "" then
key = l;
if l ~= nil and l ~= "" then
key = key .. l;
end
table.insert(nnames, key);
names = { code = l, name = l, index = l, extention = l, value = v};
cnt = cnt +1;
end
end
end
end
if cnt > 0 then
table.sort(nnames);
for i, key in ipairs(nnames) do
local v = names;
result = result .. formatLang(v.code, v.name, v.index, v.extention);
result = result .. ": " .. v.value .. "\n";
end
end
return result
end
function p.ref(frame)
local result = "";
local args = frame.args;
if args == nil then
args = frame:getParent().args;
end
local code = args;
if type(code) == 'string' then
local trimmed = trimstr(code);
local l = languages;
if l ~= nil then
result = result .. formatLang(l, l, l, l);
end
end
if result == '' then
result = tostring(code);
end
return result;
end
return p