Модуль:Картчыкълагъа функцияла
Кёрюнюую
Для документации этого модуля может быть создана страница Модуль:Картчыкълагъа функцияла/doc
--функция магъананы ичи бошмуду деб сынайды (nil неда ичи бош тизгин, неда ичи бош таблица)
function ie(var)
if(var) then
if type(var)=="string" and string.len(var)>0 then
return false
elseif type(var)=="table" and #var>0 then
return false
else
return true
end
else return true; end
end
function ine(var) return (not ie(var)); end
--сан индексге функция, сан =1 эсе тизмени къайтарады, болмаса санны кесин
function ind(x)
if(x==1) then return ""; else return tostring(x); end
end
--функція яка реалізовує тернарний оператор
function ternary(condition, if_true, if_false)
if(condition) then return if_true;
else return if_false; end
end
--функція отримує номер елемента Вікіданих і повертає посилання на відповідну статтю або просто текстову позначку
function title_for(item_id, is_a_contry)
tf_item = mw.wikibase.getEntity(item_id);
if(is_a_contry and tf_item.claims and tf_item.claims["P298"]) then
return "{{"..tf_item:getBestStatements('P298')[1].mainsnak.datavalue.value.."}}";
elseif(tf_item.sitelinks and tf_item.sitelinks.ukwiki) then
page = tf_item.sitelinks.ukwiki.title;
return "[["..page.."|"..mw.text.split(page, " %(")[1].."]]";
elseif(tf_item.labels.uk) then return tf_item.labels.uk.value;
else return ""; end
end
--функція для переведення значення часу із Вікіданих у людиночитабельний вигляд
function format_time(time_object)
str = time_object.time; precision = time_object.precision or 11;
month_names = {"январь", "февраль", "март", "апрель", "май",
"июнь", "июль", "август", "сентябрь", "октябрь", "ноябрь", "декабрь"};
month_names_gen = {"январны", "февралны", "мартны", "апрелни", "майны",
"июнну", "июлну", "августну", "сентябрны", "октябрны", "ноябрны", "декабрны"};
year = "[["..string.sub(str, 2, 5).."]]";
month = tonumber(string.sub(str, 7, 8));
day = tonumber(string.sub(str, 10, 11));
if(precision==11) then return "[["..day.." "..month_names_gen[month].."]] "..year;
elseif(precision==10) then return month_names[month]..' '..year;
elseif(precision==9) then return year;
elseif(precision==8) then return year..'-ті';
elseif(precision==7) then return (math.floor(year/100) + 1)..' ст.';
else return ""
end
end