Modul:languages
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 .. "* [[" .. mw.ustring.lower(name) .. "#Русский|" .. name .. "]]";
if index ~= nil and index ~= "" then
local indexes = {
["в"] = "восстановленный язык",
["a"] = "limbă artificială",
["р"] = "реконструированный язык",
["f"] = "limbă fictivă",
["†"] = "limbă moartă"
}
local title = indexes[index] 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['demo'];
if demo ~= nil and demo ~= "" then
for code,v in pairs(languages) do
key = v[2];
if v[4] ~= nil and v[4] ~= "" then
key = key .. v[4];
end
table.insert(nnames, key);
names[key] = { code = v[1], name = v[2], index = v[3], extention = v[4], 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[trimmed];
if l ~= nil and l ~= "" and v ~= nil and v ~= "" then
key = l[2];
if l[4] ~= nil and l[4] ~= "" then
key = key .. l[4];
end
table.insert(nnames, key);
names[key] = { code = l[1], name = l[2], index = l[3], extention = l[4], 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[key];
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[1] == nil then
args = frame:getParent().args;
end
local code = args[1];
if type(code) == 'string' then
local trimmed = trimstr(code);
local l = languages[trimmed];
if l ~= nil then
result = result .. formatLang(l[1], l[2], l[3], l[4]);
end
end
if result == '' then
result = tostring(code);
end
return result;
end
return p