A modult a Modul:Nyelvtani modul/doc lapon tudod dokumentálni
local p = {}
local lang = mw.getContentLanguage()
-- allow to call functions with a single string or number parameter
local function getArgs(frame, options)
if type(frame) ~= "table" then frame = { frame } end
return require('Modul:Arguments').getArgs(frame, options)
end
-- needed to be called from pcall
local function formatDateLocal(form, tstamp, loc)
return lang:formatDate(form, tstamp, loc)
end
-- returns "a" or "az" depending on the first character of the word passed to the template
function p.az(frame)
local str = getArgs(frame)
if not str then return "a(z)" end
local firstChar = mw.ustring.sub(str, 1, 1)
local firstCharLower = mw.ustring.lower(firstChar)
if (nil ~= mw.ustring.find("aáeéiíoóöőuúüű", firstCharLower, 1, true)) then
return "az"
elseif (nil ~= mw.ustring.find("bcdfghjklmnpqrstvwxyz", firstCharLower, 1, true)) then
return "a"
else
return "a(z)"
end
end
-- Return true if first argument starts with A or Az, otherwise empty string.
function p.startsWithAz(frame)
local s = getArgs(frame)
return (s == nil and '') or tostring(mw.ustring.upper(mw.ustring.sub(s, 1, 2)) == 'A '
or mw.ustring.upper(mw.ustring.sub(s, 1, 3)) == 'AZ '
or ''
)
end
-- returns month name in Hungarian + "ából" / "jából" / "éből" / "jéből" accordingly
function p.fromMonthSuffix(frame)
local dateStr = getArgs(frame)
local suffixes = {
= "jából",
= "jából",
= "ából",
= "ából",
= "ából",
= "ából",
= "ából",
= "ából",
= "éből",
= "éből",
= "éből",
= "éből"
}
if (pcall(formatDateLocal, 'n', dateStr)) then
local monthIndex = lang:formatDate('n', dateStr)
return lang:formatDate('Y F', dateStr)..suffixes
else
return dateStr
end
end
-- returns month name in Hungarian + "i"
function p.ofMonthSuffix(frame)
local dateStr = getArgs(frame)
if (pcall(formatDateLocal, 'n', dateStr)) then
return lang:formatDate('Y F', dateStr).."i"
else
return dateStr
end
end
-- returns number + "-s" / "-as" / "-es" / "-os" / "-ós" / "-ös"
function p.hanyas(frame)
local str = getArgs(frame);
if (nil == str) then
return ""
end
local number = tonumber(str)
if (nil == number) then
number = mw.ustring.match(str, "%d*$")
end
local suffixesNonRound = {
= "es",
= "es",
= "as",
= "es",
= "ös",
= "os",
= "es",
= "as",
= "es"
}
local suffixesRoundBelow100 = {
= "es",
= "as",
= "as",
= "es",
= "es",
= "as",
= "es",
= "as",
= "es"
}
local lastChar = mw.ustring.sub(str, -1)
local suffixIndex = tonumber(lastChar)
if (nil ~= suffixIndex) then
if (0 ~= suffixIndex) then
return str.."-"..suffixesNonRound
else
if (0 == tonumber(str) or 0 == tonumber(number)) then
-- return the parameter value + "-s" if
-- the parameter value is exactly 0 or
-- a NaN ending with a number that evaluates to 0 (like "M0" or "dsdadsa000")
return str.."-s"
elseif (0 ~= (number % 100)/10) then
suffixIndex = (number % 100)/10
return str.."-"..suffixesRoundBelow100
elseif (0 ~= (number % 1000)/100) then
return str.."-as"
elseif (0 == number % 10^36) then
return str.."-s"
elseif (0 == number % 10^33) then
return str.."-os"
elseif (0 == number % 10^30) then
return str.."-s"
elseif (0 == number % 10^27) then
return str.."-os"
elseif (0 == number % 10^24) then
return str.."-s"
elseif (0 == number % 10^21) then
return str.."-os"
elseif (0 == number % 10^18) then
return str.."-s"
elseif (0 == number % 10^15) then
return str.."-os"
elseif (0 == number % 10^12) then
return str.."-s"
elseif (0 == number % 10^9) then
return str.."-os"
elseif (0 == number % 10^6) then
return str.."-s"
elseif (0 == number % 10^3) then
return str.."-es"
end
end
end
return str
end
-- returns "-s" / "-as" / "-es" / "-os" / "-ós" / "-ös"
function p.hanyas2(frame)
local str = getArgs(frame);
if (nil == str) then
return ""
end
local number = tonumber(str)
if (nil == number) then
number = mw.ustring.match(str, "%d*$")
end
local suffixesNonRound = {
= "es",
= "es",
= "as",
= "es",
= "ös",
= "os",
= "es",
= "as",
= "es"
}
local suffixesRoundBelow100 = {
= "es",
= "as",
= "as",
= "es",
= "es",
= "as",
= "es",
= "as",
= "es"
}
local lastChar = mw.ustring.sub(str, -1)
local suffixIndex = tonumber(lastChar)
if (nil ~= suffixIndex) then
if (0 ~= suffixIndex) then
return "-"..suffixesNonRound
else
if (0 == tonumber(str) or 0 == tonumber(number)) then
-- return the parameter value + "-s" if
-- the parameter value is exactly 0 or
-- a NaN ending with a number that evaluates to 0 (like "M0" or "dsdadsa000")
return "-s"
elseif (0 ~= (number % 100)/10) then
suffixIndex = (number % 100)/10
return "-"..suffixesRoundBelow100
elseif (0 ~= (number % 1000)/100) then
return "-as"
elseif (0 == number % 10^36) then
return "-s"
elseif (0 == number % 10^33) then
return "-os"
elseif (0 == number % 10^30) then
return "-s"
elseif (0 == number % 10^27) then
return "-os"
elseif (0 == number % 10^24) then
return "-s"
elseif (0 == number % 10^21) then
return "-os"
elseif (0 == number % 10^18) then
return "-s"
elseif (0 == number % 10^15) then
return "-os"
elseif (0 == number % 10^12) then
return "-s"
elseif (0 == number % 10^9) then
return "-os"
elseif (0 == number % 10^6) then
return "-s"
elseif (0 == number % 10^3) then
return "-es"
end
end
end
return ""
end
-- returns number + "-ban" / "-ben"
function p.hanyban(frame)
local str = getArgs(frame);
if (nil == str) then
return ""
end
local number = tonumber(str)
if (nil == number) then
number = mw.ustring.match(str, "%d*$")
end
local suffixesNonRound = {
= "ben",
= "ben",
= "ban",
= "ben",
= "ben",
= "ban",
= "ben",
= "ban",
= "ben"
}
local suffixesRoundBelow100 = {
= "ben",
= "ban",
= "ban",
= "ben",
= "ben",
= "ban",
= "ben",
= "ban",
= "ben"
}
local lastChar = mw.ustring.sub(str, -1)
local suffixIndex = tonumber(lastChar)
if (nil ~= suffixIndex) then
if (0 ~= suffixIndex) then
return str.."-"..suffixesNonRound
else
if (0 == tonumber(str) or 0 == tonumber(number)) then
-- return the parameter value + "-s" if
-- the parameter value is exactly 0 or
-- a NaN ending with a number that evaluates to 0 (like "M0" or "dsdadsa000")
return str.."-ban"
elseif (0 ~= (number % 100)/10) then
suffixIndex = (number % 100)/10
return str.."-"..suffixesRoundBelow100
elseif (0 ~= (number % 1000)/100) then
return str.."-ban"
elseif (0 == number % 10^6) then
return str.."-ban"
elseif (0 == number % 10^3) then
return str.."-ben"
end
end
end
return str
end
-- converts default signature timestamp to YYYY-MM-DD HH:MM (T) format for
-- further processing via {{#time:}}
function p.alairasIdobelyeg(frame)
local str = getArgs(frame)
if type(str) ~= 'string' then return str, nil end;
local months = {
= 1,
= 2,
= 3,
= 4,
= 5,
= 6,
= 7,
= 8,
= 9,
= 10,
= 11,
= 12
}
local match = {
tonumber(mw.ustring.match(str, '(%d%d%d%d)%. %a+ %d?%d%.%, %d%d%:%d%d %(CES?T%)')),
months ,
tonumber(mw.ustring.match(str, '%d%d%d%d%. %a+ (%d?%d)%.%, %d%d%:%d%d %(CES?T%)')),
tostring(mw.ustring.match(str, '%d%d%d%d%. %a+ %d?%d%.%, (%d%d%:%d%d %(CES?T%))'))
}
if #match ~= 4 or match == nil then
return str, nil
end
str = mw.ustring.format( '%d-%d-%d %s', match, match, match, match)
return mw.getContentLanguage():formatDate('Y-m-d H:i (T)', str, true)
end
-- creates a list from (any number of) unnamed arguments using separators
-- in named arguments ("elválasztó" and "utolsó" for last) or default values
-- with Scribunto function mw.text.listToText()
function p.lista(frame)
local format_params = 0
local function get_params(str)
local params = {}
for i = 1, format_params do
table.insert(params, str)
end
return unpack(params)
end
local args = getArgs(frame)
local list = {}
local format = args
if format then
for _ in format:gmatch('%%') do
format_params = format_params + 1
end
end
local max_i = 0
for n, _ in pairs(args) do
if type(n) == 'number' and n > max_i then
max_i = n
end
end
for i = 1, max_i do
if args then
if format then
table.insert(list, format:format(get_params(args)))
else
table.insert(list, args)
end
end
end
return mw.text.listToText(list, args, args)
end
return p