Module:Wt/cu/PartOfSpeech

From Wikimedia Incubator

Documentation for this module may be created at Module:Wt/cu/PartOfSpeech/doc

-- Copied and adapted from [[el:Module:PartOfSpeech]] (oldid=3350603)
--
-- Author : [[el:User:Xoristzatziki]]
-- Adaptation : [[en:User:Vvs-dm]]
-- 
-- 2017-03-29 -- last modified by Vvs-dm
--
-- Original text - Greek, French

p = {}

local languages =  mw.loadData("Module:Wt/cu/Languages")
--Module που θα επεκταθεί σιγά σιγά και θα περιέχει συναρτήσεις για κάθε γλώσσα που έχουμε
local ascii = require "Module:Wt/cu/KleidaAll"
--Τώρα περιέχει συναρτήσεις για τις παρακάτω γλώσσες
-- 'fr', 'de', 'es', 'ro', 'pt', 'tr', 'eo', 'vi'  }

--λίγο εκνευριστικό αλλά...
function exeikati(onearg)
    return not (onearg == nil or mw.ustring.len(onearg) < 1)
end

errorhere = function(errstring)
    return '<div class="error">' .. errstring .. '</div>[[Category:Pages with module errors]]'
end

pos = {}
pos['антѡнѷмъ'] = { ['link'] = '[[антѡнѷмъ|Антѡнѷмъ]]', ['category'] = 'Антѡнѷма', ['inlangu'] = true}
pos['арѳръ'] = { ['link'] = '[[арѳръ|Арѳръ]]', ['category'] = 'Арѳра', ['inlangu'] = true}
pos['арїѳмъ'] = { ['link'] = '[[арїѳмъ|Арїѳмъ]]', ['category'] = 'Арїѳмꙑ', ['inlangu'] = true}
pos['героундии'] = { ['link'] = '[[героундии|Героундии]]', ['category'] = 'Героундиꙗ', ['inlangu'] = false}
pos['єпїѳєтъ'] = { ['link'] = '[[єпїѳєтъ|Єпїѳєтъ]]', ['category'] = 'Єпїѳєта', ['inlangu'] = true}
pos['єпїѳима'] = { ['link'] = '[[єпїѳима|Єпїѳима]]', ['category'] = 'Єпїѳимꙑ', ['inlangu'] = true}
pos['єпїрима'] = { ['link'] = '[[єпїрима|Єпїрима]]', ['category'] = 'Єпїримꙑ', ['inlangu'] = true}
pos['єпїфѡнима'] = { ['link'] = '[[єпїфѡнима|Єпїфѡнима]]', ['category'] = 'Єпїфѡнимꙑ', ['inlangu'] = true}
pos['мєтєхь'] = { ['link'] = '[[мєтєхь|Мєтєхь]]', ['category'] = 'Μєтєхи', ['inlangu'] = true}
pos['чѧсть'] = { ['link'] = '[[чѧсть|Чѧсть]]', ['category'] = 'Чѧсти', ['inlangu'] = true}
pos['оусїастїкъ'] = { ['link'] = '[[оусїастїкъ|Оусїастїкъ]]', ['category'] = 'Оусїастїка', ['inlangu'] = true}
pos['парємїꙗ'] = { ['link'] = '[[парємїꙗ|Парємїꙗ]]', ['category'] = 'Парємїѩ', ['inlangu'] = true}
pos['проѳєсь'] = { ['link'] = '[[проѳєсь|Проѳєсь]]', ['category'] = 'Проѳєси', ['inlangu'] = true}
pos['проѳима'] = { ['link'] = '[[проѳима|Проѳима]]', ['category'] = 'Проѳимꙑ', ['inlangu'] = true}
pos['рима'] = { ['link'] = '[[рима|Рима]]', ['category'] = 'Рримꙑ', ['inlangu'] = true}
pos['сѷмволъ'] = { ['link'] = '[[сѷмволъ|Сѷмволъ]]', ['category'] = 'Сѷмвола', ['inlangu'] = true}
pos['сѷндєсмъ'] = { ['link'] = '[[сѷндєсмъ|Сѷндєсмъ]]', ['category'] = 'Сѷндєсма', ['inlangu'] = true}
pos['фрась'] = { ['link'] = '[[Викиаꙁъбоукъвьникъ:Фраси|Фрась]]', ['category'] = 'фраси', ['inlangu'] = false}
pos['грама'] = { ['link'] = '[[грама|Грама]]', ['category'] = 'Грамꙑ', ['inlangu'] = true}

--η κύρια συνάρτηση που θα χρησιμοποιηθεί στο Πρότυπο
function p.partofspeech(frame)
    local args = frame.args
    local lemmaargs = frame:getParent().args
    local pagename = mw.title.getCurrentTitle().text
    --μέρος του λόγου από το πρότυπο
    local part = args[1]

    --γλώσσα από το λήμμα
    local lang = lemmaargs[1] or ''
	--αν δεν υπάρχει κάτι καταχωρισμένο στον πίνακα εδώ
	--για το συγκεκριμένο μέρος του λόγου
    if not exeikati(pos[part]['category']) then
    	return errorhere('The part of speech is not supported by this template. Please make sure the chosen part of speech is added to the Module:Wt/cu/PartOfSpeech')	
    end
    --βάλε την εικόνα, την αρχή του span και το μέρος του λόγου
    local output = '[[File:Open book 01.svg|30x30px|link=]]<span class="partofspeech"> ' .. pos[part]['link']
    --αν έχει αρίθμηση βάλε και ένα κενό συν τον αριθμό
    if exeikati(lemmaargs['no']) then        
        output = output  .. ' ' .. lemmaargs['no']
    end
    --κλείσε το span
    output = output  .. '</span>'
    --Συνέχισε με τις κατηγορίες μόνο για το κύριο namespace
    if mw.title.getCurrentTitle().nsText ~= '' then return output end
    --αν δεν έχει δοθεί γλώσσα ή δεν υπάρχει στον πίνακα των γλωσσών ο κωδικός ή/και το name
    if lang == '' or languages[lang] == nil then
        return pos[part]['link']..'[[Category:Pages with language code errors]]'
	--Δεν δόθηκε κωδικός γλώσσας ή δεν είναι καταχωρισμένος στον πίνακα.')	
	end
    
    local kleida = ''
    --Αν ο χρήστης μάς έχει δώσει κλείδα, σαν δεύτερη αριθμητική παράμετρο στο λήμμα, την χρησιμοποιούμε
    if exeikati(lemmaargs[2]) then
        kleida = '|' .. lemmaargs[2]
        --διαφορετικά κοιτάμε αν υπάρχει ετοιμη συνάρτηση για τη συγκεκριμένη γλώσσα
    elseif ascii.kleida[lang] ~= nil then
        kleida = '|' .. ascii.kleida[lang](pagename)
    end
    if not exeikati(pos[part]['category']) then  
    	return errorhere('Not registered category in the Module:Wt/cu/PartOfSpeech.')	
	else		
        output = output  .. '[[Category:' .. pos[part]['category'] .. ' (' .. languages[lang].cat .. ')' .. kleida .. ']]'
        if pos[part]['inlangu'] then
            output = output  .. '[[Category:' .. languages[lang].cat .. kleida .. ']]'
        end
    end
    return frame:preprocess(output)
end

function p.get_name(frame)
	local lang = frame.args[1];													-- get language code argument from wikitext arguments table
	
    -- Pas de code langue ? Renvoie nil.
    if (lang == nil) then return nil end
    
    -- Espaces avant et après enlevés
     lang = mw.text.trim(lang)
    
    -- Récupère la table des langues entière (en cache)
    local languages = mw.loadData('Module:Wt/cu/Languages')
    
    -- A-t-on la langue correspondant au code donné ?
    if (languages[lang] and languages[lang]['name']) then
        -- Trouvé ! Renvoie le nom
        return languages[lang]['name']
    else
        -- Pas trouvé : on renvoie nil
        return nil
    end
end

return p