Modul:langlist
Görünüş
Bu modulun sənədləşdirmə səhifəsi Modul:langlist/doc səhifəsində yaradıla bilər
-- Dillərin tərcüməsi siyahısını yaratmaq üçün modul
-- Dillərin bu modula uyğun cədvəl şəklində yüklənməsi
local languages = mw.loadData("Module:langlist/data");
local p = {};
-- yardımçı funksiya, boşluqları silir
local function trimstr(s)
return (s:gsub("^%s*(.-)%s*$", "%1"));
end
local function formatLang(code, name, index, extention)
local result = '';
local margin = '';
result = result .. "* ".. name .."";
if index ~= nil and index ~= "" then
local indexes = {
["b"] = "bərpa olunmuş dil",
["s"] = "süni dil",
["y"] = "yenilənmiş dil",
["f"] = "fantastik dil",
["†"] = "ölü dil"
}
local title = indexes[index] or '';
if title ~= '' then
title = " title='" .. title .. "'";
end
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