„Modul:Nyelvtani modul” változatai közötti eltérés

A Wikipédiából, a szabad enciklopédiából
[ellenőrzött változat][ellenőrzött változat]
Tartalom törölve Tartalom hozzáadva
aNincs szerkesztési összefoglaló
paraméterek tömbbé alakítása külön függvénnyel, nem table paraméter is működik (string mindenhol, szám hanyas, hanyban függvényeknél, többinél nem egyszerű számra van szükség)
1. sor: 1. sor:
local p = {}
local p = {}
local lang = mw.getContentLanguage()
local lang = mw.getContentLanguage()

function getArgs(frame, options)
if type(frame) == "table" then
return require('Modul:Arguments').getArgs(frame, options)
else
return { frame }
end
end


-- needed to be called from pcall
-- needed to be called from pcall
9. sor: 17. sor:
-- returns "a" or "az" depending on the first character of the word passed to the template
-- returns "a" or "az" depending on the first character of the word passed to the template
function p.az(frame)
function p.az(frame)
parent = frame:getParent()
str = getArgs(frame)[1]
args = parent.args
str = args[1]
firstChar = mw.ustring.sub(str, 1, 1)
firstChar = mw.ustring.sub(str, 1, 1)
28. sor: 34. sor:
-- Return true if first argument starts with A or Az, otherwise empty string.
-- Return true if first argument starts with A or Az, otherwise empty string.
function p.startsWithAz(frame)
function p.startsWithAz(frame)
local s = frame.args[1]
local s = getArgs(frame)[1]
return (s == nil and '') or tostring(mw.ustring.upper(mw.ustring.sub(s, 1, 2)) == 'A '
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 mw.ustring.upper(mw.ustring.sub(s, 1, 3)) == 'AZ '
37. sor: 43. sor:
-- returns month name in Hungarian + "ából" / "jából" / "éből" / "jéből" accordingly
-- returns month name in Hungarian + "ából" / "jából" / "éből" / "jéből" accordingly
function p.fromMonthSuffix(frame)
function p.fromMonthSuffix(frame)
parent = frame:getParent()
dateStr = getArgs(frame)[1]
args = parent.args
dateStr = args[1]
suffixes = {
suffixes = {
[1] = "jából",
[1] = "jából",
67. sor: 71. sor:
-- returns month name in Hungarian + "i"
-- returns month name in Hungarian + "i"
function p.ofMonthSuffix(frame)
function p.ofMonthSuffix(frame)
parent = frame:getParent()
dateStr = getArgs(frame)[1]
args = parent.args
dateStr = args[1]
if (pcall(formatDateLocal, 'n', dateStr)) then
if (pcall(formatDateLocal, 'n', dateStr)) then
81. sor: 83. sor:
-- returns number + "-s" / "-as" / "-es" / "-os" / "-ós" / "-ös"
-- returns number + "-s" / "-as" / "-es" / "-os" / "-ós" / "-ös"
function p.hanyas(frame)
function p.hanyas(frame)
parent = frame:getParent()
str = getArgs(frame)[1];
args = parent.args
str = args[1];
if (nil == str) then
if (nil == str) then
170. sor: 170. sor:
-- returns number + "-ban" / "-ben"
-- returns number + "-ban" / "-ben"
function p.hanyban(frame)
function p.hanyban(frame)
parent = frame:getParent()
str = getArgs(frame)[1];
args = parent.args
str = args[1];
if (nil == str) then
if (nil == str) then

A lap 2014. október 18., 00:18-kori változata

Nyelvtani modul[mi ez?] • [dokumentáció: mutat, szerkeszt] • [tesztek: sikeres: 1, sikertelen: 1, kihagyva: 0 (részletek)]

Előfordulások

local p = {}
local lang = mw.getContentLanguage()

function getArgs(frame, options)
	if type(frame) == "table" then
		return require('Modul:Arguments').getArgs(frame, options)
	else
		return { frame }
	end
end

-- needed to be called from pcall
function formatDateLocal(form, tstamp, loc)
   return lang:formatDate('n', dateStr, loc)
end

-- returns "a" or "az" depending on the first character of the word passed to the template
function p.az(frame)
    str = getArgs(frame)[1]
    
    firstChar = mw.ustring.sub(str, 1, 1)
    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)[1]
	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)
    dateStr = getArgs(frame)[1]
    suffixes = {
        [1] = "jából",
        [2] = "jából",
        [3] = "ából",
        [4] = "ából",
        [5] = "ából",
        [6] = "ából",
        [7] = "ából",
        [8] = "ából",
        [9] = "éből",
        [10] = "éből",
        [11] = "éből",
        [12] = "éből"
    }
    
    
    if (pcall(formatDateLocal, 'n', dateStr)) then
        monthIndex = lang:formatDate('n', dateStr)
        return lang:formatDate('Y F', dateStr)..suffixes[tonumber(monthIndex)]
    else
        return dateStr
    end

end

-- returns month name in Hungarian + "i"
function p.ofMonthSuffix(frame)
    dateStr = getArgs(frame)[1]    
    
    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)
    str = getArgs(frame)[1];
    
    if (nil == str) then
        return ""
    end    
    
    number = tonumber(str)
    if (nil == number) then
        number = mw.ustring.match(str, "%d*$")
    end

    suffixesNonRound = {
        [1] = "es",
        [2] = "es",
        [3] = "as",
        [4] = "es",
        [5] = "ös",
        [6] = "os",
        [7] = "es",
        [8] = "as",
        [9] = "es"
    }
    
    suffixesRoundBelow100 = {
        [1] = "es",
        [2] = "as",
        [3] = "as",
        [4] = "es",
        [5] = "es",
        [6] = "as",
        [7] = "es",
        [8] = "as",
        [9] = "es"
    }

    lastChar = mw.ustring.sub(str, -1)

    suffixIndex = tonumber(lastChar)
    
    if (nil ~= suffixIndex) then
        if (0 ~= suffixIndex) then
            return str.."-"..suffixesNonRound[suffixIndex]
        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[suffixIndex]
            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 number + "-ban" / "-ben"
function p.hanyban(frame)
    str = getArgs(frame)[1];
    
    if (nil == str) then
        return ""
    end    
    
    number = tonumber(str)
    if (nil == number) then
        number = mw.ustring.match(str, "%d*$")
    end

    suffixesNonRound = {
        [1] = "ben",
        [2] = "ben",
        [3] = "ban",
        [4] = "ben",
        [5] = "ben",
        [6] = "ban",
        [7] = "ben",
        [8] = "ban",
        [9] = "ben"
    }
    
    suffixesRoundBelow100 = {
        [1] = "ben",
        [2] = "ban",
        [3] = "ban",
        [4] = "ben",
        [5] = "ben",
        [6] = "ban",
        [7] = "ben",
        [8] = "ban",
        [9] = "ben"
    }

    lastChar = mw.ustring.sub(str, -1)

    suffixIndex = tonumber(lastChar)
    
    if (nil ~= suffixIndex) then
        if (0 ~= suffixIndex) then
            return str.."-"..suffixesNonRound[suffixIndex]
        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[suffixIndex]
            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

return p