Module:Χρήστης:Xoristzatziki:τεστμτφ

Documentation for this module may be created at Module:Χρήστης:Xoristzatziki:τεστμτφ/τεκμηρίωση

local export = {}

local languages = mw.loadData("Module:Languages")
local kleida = require "Module:Kleida-el"

function split(pString, pPattern)
   local Table = {}
   local fpat = "(.-)" .. pPattern
   local last_end = 1
   local s, e, cap = pString:find(fpat, 1)
   while s do
       if s ~= 1 or cap ~= "" then
           table.insert(Table,cap)
       end
	   last_end = e+1
	   s, e, cap = pString:find(fpat, last_end)
   end
   if last_end <= #pString then
       cap = pString:sub(last_end)
	   table.insert(Table, cap)
   end
   return Table
end
--ταξινομεί τον πίνακα μεταφράσεων με βάση την ονομασία της γλώσσας
--(είτε έχει είτε δεν έχει μετάφραση η γλώσσα)
function export.show(title)
    local ret = ""
    local text = mw.title.makeTitle(0, title):getContent()
    local lines_ = split(text, "\n")
    local neo = {}
    local axrhsta = {}
    local captureisoblank = '<!%-%-%s{{(%a*)}}'
    local captureiso = '%*%s{{(%a*)}}'
    local findpatternstart = '{{μτφ-αρχή'
    local findpatternend = '{{μτφ-τέλος'
    
    local linecounter = 0
    local inside = false
    local telos = false
    local output = '<pre>'
    local mtfstart ='{{μτφ-'
    output = output .. tostring(#lines_)
    othercounter = 0
    for xcounter,line in ipairs(lines_) do
        
        --output = output .. line .. findpattern3 ..'\n'
        local xstart1, xend, firstcapture, arxi =  mw.ustring.find(line, findpatternstart, 0,true)
        if xstart1 then
        	inside = true
        	output = output .. line
    	end
    	
        if inside then
            
            local xstart2, xend2, firstcapture2, brhkatelos =  mw.ustring.find(line, findpatternend, 0, true)
            if xstart2 then
                inside = false
                telos = true
            end
            if telos then break end
            local xstart3, xend3, firstcapture3, langcaptured =  mw.ustring.find(line, captureisoblank, 1)
            local xstart4, xend4, firstcapture4, langcaptured2 =  mw.ustring.find(line, captureiso, 1)
            langexists = xstart3 or xstart4 or ''
            if langexists then
            	linecounter = linecounter + 1
                langiso = firstcapture3 or firstcapture4
                othercounter = othercounter+1
                --if xstart3 then
                	--langiso = mw.ustring.sub(line,xstart3,xend3)
                --else
                	--langiso = mw.ustring.sub(line,xstart4,xend4)
            	--end
            	--table.insert(neo,{ linelang = langiso,linetext = line})
                if languages[langiso] then
				    table.insert(neo,{ linelang = kleida.kleidaleksis(languages[langiso].name),linetext = line})
			    else
				    if (mw.ustring.sub(line,1,mw.ustring.len(mtfstart)) ~= mtfstart) then table.insert(axrhsta,line) end
			    end
            end
        end
    end

    function compkleida(w1,w2)
    	return w1['linelang'] < w2['linelang']
	end
    table.sort(neo, compkleida)
    table.insert(neo,(linecounter / 2)+1,{ linelang = '',linetext = '{{μτφ-μέση}}'})
    
    for xcounter,line in ipairs(neo) do
        output = output .. '\n' .. line.linetext 
    end
    
    --output = output .. '\nlinecounter:' .. tostring(linecounter) .. '\n\nΤΕΛΟΣ ΜΕΤΑΦΡΑΣΕΩΝ\n\n'
    
    if #axrhsta then
        output =  output .. '\n  Λανθασμένα.....' 
        for xcounter,line in ipairs(axrhsta) do
            output =  output .. '\n' .. line
        end
        --output =  output .. '\n' .. tostring(#axrhsta )
    end
    return output .. '</pre>'  
end
function export.show2(frame)
	local templateargs = frame.args
	return export.show(templateargs[1])
end
return export