Module:topos >> Module:topos/kind     <<   Module:topos/τεκμηρίωση (documentation) <<
Module:topos >> Module:topos/where
Module:topos >> Module:topos/functions
Το Module καλείται από το Πρότυπο:τόπος όπου υπάρχουν οδηγίες. Δείτε και την Κατηγορία:Τοπωνύμια.
Επιμέρους functions, χρήσιμες σε άλλα Modules υπάρχουν στο Module:topos/functions


--[=[
2020.06.06. Sarri.greek. Language:Greek
	Module για τοπωνύμια. Εμφανίζει μικρή φράση και εντάσσει σε Κατηγορίες.
	To display phrase and create Categories for placenames.
	cf [[Template:τόπος]]
	Παράμετροι υποχρεωτικές: 1=lang_iso, 2=word (kind of place), 3=area
[[Πρότυπο:τόπος/τεστ]]
	
ΕΚΚΡΕΜΟΤΗΤΕΣ - to do
	* 
	
PROBLEMS (are marked with ??)
	* Cannot disginguish between
		a. empty (editor leaves an empty place or, writes nothing)
		and b. nil or WRONG (the term is not included in the data page)
		So, an error message cannot be applied.

]=]--


p = {}

local languages = mw.loadData("Module:Languages")
local kind = require("Module:topos/kind") -- Must they be the same name?? kind, /kind??
local where = require("Module:topos/where")	-- Must they be the same name??
-- m_data = require("Module:topos/data") -- Could they above two be combined in one page?? What do we write here??


-- this is copied from many Modules. Don't know what it does, but it helps for 'errors'
function thing(onearg)
    return not (onearg == nil or mw.ustring.len(onearg) < 1)
end

-- why not 'local' errorhere??
errorhere = function(errstring)
    return '<div class="error">' .. errstring .. '</div>[[Κατηγορία:Σελίδες με σφάλματα στο Πρότυπο:τόπος]]'
end


function p.main(frame)
--    local args = frame.args	-- is this needed? 
    local args = frame:getParent().args
    local lang_iso = args[1] or ''
if lang_iso == '' or lang_iso == nil then lang_iso = 'el' end -- el, modern greek is assumed --Why is not this valid from now onwards everywhere??
	local lang_name = languages[lang_iso].name or ''
    local word = args[2] or '' -- word displayed: the kind of place
if word == '' or word == nil then word = 'τοπωνύμιο' end
	local kind_cat = args['kind_cat'] or ''
	local plural = args['πλ'] or args['pl'] or ''
	local area = args[3] or ''
	local area_show = args['area_show'] or args['πού_εμφ'] or args['που_εμφ'] or '' -- this is too difficult to type
	local area_show_not = args['0'] or ''
	local area_cat = args['area_cat'] or ''
	local super = args['cont'] or args['ηπ'] or args['ήπ'] or '' -- continents, ήπειροι
--	local area_cat_gen = args['area_cat_gen'] or '' --was a thought of variating accusative (in Greece) and genitive (of Greece)
		-- reluctantly, the genitive form was selected as common to every type of phrase
	local show = args[4] or args['show'] or args['εμφ'] or ''
	local nocat = args['nocat'] or args['00'] or ''
	local nodisplay = args['nodisplay'] or args['000'] or ''
	local sort = args['sort'] or args['ascii'] or ''
	local label = args['ετικ'] or ''
	

-- ???? HOW??  
--    if lang_name == '' or lang_name == nil then
--       return errorhere('Language code not found') .. '[[Κατηγορία:Σελίδες με σφάλμα στον κωδικό γλώσσας]]' 	--Δεν δόθηκε κωδικός γλώσσας ή δεν είναι καταχωρισμένος στον πίνακα.')	
--    end

--    if kind[word]['word'] IS WRONG then
--    	return errorhere('Το είδος αυτό δεν υπάρχει στον πίνακα.')
-- 	end

-- works, but it spoils everything else
--    if not thing(kind[word]['word']) then
--    	return errorhere('Το είδος αυτό δεν υπάρχει στον πίνακα.')	
--    end


----------------------------------------------------------------------------
--                        ΚΕΙΜΕΝΟ / TEXT                                  --
----------------------------------------------------------------------------
if nodisplay ~= '' then		-- parameter |000=-
		output = ''
else

	
	if show ~= '' then
		if plural == '1' then
		output = '[[' .. kind[word]['word'] .. '|' .. kind[word]['word_pl'] ..']]'
		else
		output = '[[' .. kind[word]['word'] .. '|' .. show ..']]'
		end
    else
    	if plural == '1' then
		output = '[[' .. kind[word]['word'] .. '|' .. kind[word]['word_pl'] ..']]'
		else
       	output = '[[' .. kind[word]['word'] .. ']]'
       	end
	end
-- if label ετικέτα
	if args['ετικ'] == '1' then
		output = '(<i>' .. output .. '</i>)'
	elseif args['ετικ'] == '+' then
		output = '(<i>[[τοπωνύμιο]], ' .. output .. '</i>)'
	else
		
	-- extra text in genitive 'της ...' about the Area used in the TEXT and in the CATEGORY
	if area ~= '' and (area_show == '0' or area_show_not ~= '') then
		output = output .. ''
	elseif area ~= '' and (area_show ~= '0' or area_show_not == '') then
		output = output .. ' ' .. where[area]['word']
	end
	
	if args['ετικ'] == 'τοπ' then
		output = '(<i>[[τοπωνύμιο]]</i>) ' .. output
	end
	end -- close ετικέτα = 1 & ετικέτα = +
	
end -- close nodisplay


----------------------------------------------------------------------------
--               ΚΑΤΗΓΟΡΙΕΣ / CATEGORIES                                 --
----------------------------------------------------------------------------

if nocat ~= '' then			-- parameter |00=-
	output = output .. ''
else
	
-- first, an exception:
-- ===================== πρωτεύουσες / capital cities  ======================= --
	-- if πρωτεύουσα, ζητάμε ή πού= ή χώρα=
	-- Special: when cities are capitals. |where= (continent) or |country=
	-- check Παρίσι (εε) Λονδίνο (Αγγλία>Μεγάλη Βρετανία>Ευρώπη) Κάιρο (Αφρική)
	-- check Εδιμβούργο (Σκοτία χώρα=Βρετανία), Βαρκελώνη
	-- check Θεσσαλονίκη (with blank where: {{τόπος|el|πρωτεύουσα|-|χώρα=Ελλάδα}})
	-- check Βόλος (just a city)
	if word == 'πρωτεύουσα' then

		local country = args['country'] or args['χώρα'] or '' -- για τοπικές πρωτεύουσες
		local capital = args['capital'] or args['πρωτ'] or args['where'] or args['πού'] or args['που']  or ''

-- none
		if country == '' and capital == '' then
			output = errorhere('Επιλέξτε τύπο περιοχής: |πού=(ήπειρος) ή |χώρα= αν είναι τοπική πρωτεύουσα')
-- both
		elseif country ~= '' and capital ~= '' then
			output = errorhere('Διαλέξτε ένα από τους δύο τύπους: |πού=(ήπειρος) ή |χώρα=...')
-- |πού= (ήπειρος, για χώρες)
		elseif country == '' and capital ~= '' then
			output = output .. '[[Κατηγορία:Πρωτεύουσες' .. ' ' .. where[capital]['word_cat'] .. ' (' .. languages[lang_iso].name .. ')]]'
		.. '[[Κατηγορία:Πόλεις' .. ' ' .. where[area]['word_cat'] .. ' (' .. languages[lang_iso].name .. ')]]'
		.. '[[Κατηγορία:Πρωτεύουσες' .. ' (' .. languages[lang_iso].name .. ')]]'
		.. '[[Κατηγορία:Πόλεις' .. ' (' .. languages[lang_iso].name .. ')]]'
		.. '[[Κατηγορία:Τοπωνύμια' .. ' ' .. where[area]['word_cat'] .. ' (' .. languages[lang_iso].name .. ')]]'
--		.. '[[Κατηγορία:Τοπωνύμια' .. ' ' .. where[capital]['word_cat'] .. ' (' .. languages[lang_iso].name .. ')]]'

-- |χώρα= (χώρα, για τοπικές πρωτεύουσες) check [[Βαρκελώνη]] / Πόλεις-πρωτεύουσες with hyphen ia a PROBLEM for [[Module:auto cat]]
		elseif country ~= '' and capital == ''then
		output = output .. '[[Κατηγορία:Τοπικές πρωτεύουσες' .. ' ' .. where[country]['word_cat'] .. ' (' .. languages[lang_iso].name .. ')]]'
		.. '[[Κατηγορία:Πόλεις' .. ' ' .. where[country]['word_cat'] .. ' (' .. languages[lang_iso].name .. ')]]'
		.. '[[Κατηγορία:Πόλεις' .. ' ' .. where[area]['word_cat'] .. ' (' .. languages[lang_iso].name .. ')]]'
		.. '[[Κατηγορία:Πόλεις' .. ' (' .. languages[lang_iso].name .. ')]]'
		.. '[[Κατηγορία:Τοπωνύμια' .. ' ' .. where[area]['word_cat'] .. ' (' .. languages[lang_iso].name .. ')]]'
		.. '[[Κατηγορία:Τοπωνύμια' .. ' ' .. where[country]['word_cat'] .. ' (' .. languages[lang_iso].name .. ')]]'
		end



else -- ALL the others:


	if area ~= '' then
		if sort ~= '' then
		output = output .. '[[Κατηγορία:' .. kind[word]['word_cat'] .. ' ' .. where[area]['word_cat'] .. ' (' .. languages[lang_iso].name .. ')|' .. sort .. ']]'
		.. '[[Κατηγορία:' .. kind[word]['word_cat'] .. ' (' .. languages[lang_iso].name .. ')|' .. sort .. ']]'
		.. '[[Κατηγορία:Τοπωνύμια' .. ' ' .. where[area]['word_cat'] .. ' (' .. languages[lang_iso].name .. ')|' .. sort .. ']]'
		.. '[[Κατηγορία:Τοπωνύμια' .. ' (' .. languages[lang_iso].name .. ')|' .. sort .. ']]'
			if word ~= '' and kind[word]['word_cat1'] ~= '' and  kind[word]['word_cat1'] ~= nil then
				output = output .. '[[Κατηγορία:' .. kind[word]['word_cat1'] .. ' (' .. languages[lang_iso].name .. ')|' .. sort .. ']]'
			elseif word ~= '' and kind[word]['word_cat1'] == '' and  kind[word]['word_cat1'] == nil then
				output = output
			end
		else
		output = output .. '[[Κατηγορία:' .. kind[word]['word_cat'] .. ' ' .. where[area]['word_cat'] .. ' (' .. languages[lang_iso].name .. ')]]'
		.. '[[Κατηγορία:' .. kind[word]['word_cat'] .. ' (' .. languages[lang_iso].name .. ')]]'
		.. '[[Κατηγορία:Τοπωνύμια' ..  ' ' .. where[area]['word_cat'] .. ' (' .. languages[lang_iso].name .. ')]]'
		.. '[[Κατηγορία:Τοπωνύμια' .. ' (' .. languages[lang_iso].name .. ')]]'
			if word ~= '' and kind[word]['word_cat1'] ~= '' and  kind[word]['word_cat1'] ~= nil then
				output = output .. '[[Κατηγορία:' .. kind[word]['word_cat1'] .. ' (' .. languages[lang_iso].name .. ')]]'
			elseif word ~= '' and kind[word]['word_cat1'] == '' and  kind[word]['word_cat1'] == nil then
				output = output
			end
		end -- close sort
		
	else -- if no area

-- ===================== Εξαιρούνται από το 'περιοχή' ======================= --	
-- excecptions: 'where' is not needed	
-- εξαιρούνται από το υποχρεωτικό 'περιοχή'	α..ω:	
if word == 'ήπειρος' or word == 'πλανήτης' or word == 'ωκεανός' then

		if sort ~= '' then
		output = output .. '[[Κατηγορία:' .. kind[word]['word_cat']  .. ' (' .. languages[lang_iso].name .. ')|' .. sort .. ']]'
		.. '[[Κατηγορία:Τοπωνύμια' .. ' (' .. languages[lang_iso].name .. ')|' .. sort .. ']]'
			if word ~= '' and kind[word]['word_cat1'] ~= '' and  kind[word]['word_cat1'] ~= nil then
				output = output .. '[[Κατηγορία:' .. kind[word]['word_cat1'] .. ' (' .. languages[lang_iso].name .. ')|' .. sort .. ']]'
				.. '[[Κατηγορία:Τοπωνύμια χωρίς περιοχή στο Πρότυπο:τόπος]]' -- __HIDDENCAT__
			elseif word ~= '' and kind[word]['word_cat1'] == '' and  kind[word]['word_cat1'] == nil then
				output = output
			end
		else
		output = output .. '[[Κατηγορία:' .. kind[word]['word_cat'] .. ' (' .. languages[lang_iso].name .. ')]]'
		.. '[[Κατηγορία:Τοπωνύμια' .. ' (' .. languages[lang_iso].name .. ')]]'
--		.. '[[Κατηγορία:Τοπωνύμια χωρίς περιοχή στο Πρότυπο:τόπος]]'
			if word ~= '' and kind[word]['word_cat1'] ~= '' and  kind[word]['word_cat1'] ~= nil then
				output = output .. '[[Κατηγορία:' .. kind[word]['word_cat1'] .. ' (' .. languages[lang_iso].name .. ')]]'
			elseif word ~= '' and kind[word]['word_cat1'] == '' and  kind[word]['word_cat1'] == nil then
				output = output
			end
		end -- close sort

else -- if no exceptions	
	output = errorhere('Προσθέστε την Περιοχή! Add the area!')
	
end -- close the exceptions


	end -- close area
	
	
end -- close EXEPTION for capitals, and regional capitals

-- OTHER SPECIALS

-- ===================== Ευρωπαϊκή Ένωση / εε ======================= --	
	-- ειδικός χειρισμός χωρών στην Ευρωπαϊκή Ένωση
	-- Special: when countries are European Union |εε
	-- check Αυστρία, Austria
	if word == 'χώρα' and area == 'εε' then
		output = output .. '[[Κατηγορία:Χώρες της Ευρωπαϊκής Ένωσης' .. ' (' .. languages[lang_iso].name .. ')]]'
--			.. '[[Κατηγορία:Χώρες της Ευρώπης' .. ' (' .. languages[lang_iso].name .. ')]]'
--			.. '[[Κατηγορία:Χώρες' .. ' (' .. languages[lang_iso].name .. ')]]'
	end
	
-- ===================== Ρωσία = Ευρώπη/Ασία  ======================= --	
	-- Russia in Europe, in Asia (add extra2 for 'Russia')
	-- [[Ιρκούτσλ]]
	if area == 'Ρωσία στην Ευρώπη' or area == 'Ρωσία στην Ασία' then
		output = output .. '[[Κατηγορία:' .. kind[word]['word_cat'] .. ' της Ρωσίας (' .. languages[lang_iso].name .. ')]]'
	end
	
	

-- ===================== where word_cat1 ======================= --
-- AREA UPPER LEVEL
	 -- εάν υπάρχει υπερώνυμη Κατηγορία Περιοχής, να προστεθεί η Κατηγορία της
	 -- if there is an upper level Category of area, it is added
	if  area ~= '' and where[area]['word_cat1'] ~= '' and  where[area]['word_cat1'] ~= nil then
		output = output .. '[[Κατηγορία:' .. kind[word]['word_cat'] .. ' ' .. where[area]['word_cat1'] .. ' (' .. languages[lang_iso].name .. ')]]'
	elseif (area == '' and area == nil) and where[area]['word_cat1'] == '' and  where[area]['word_cat1'] == nil then
		output = ouput
	end

-- ===================== kind cat_super ======================= --
-- KIND SUPER = adds an upper area
	-- εάν υπάρχει μαρκάρισμα cat_super στο /kind, προσθέτει αν θέλει ο συντάκτης Κατηγορία για την ήπειρο (π.χ. της Ασίας, της Ευρώπης)
	-- if there is a cat_super marking at /kind, Categories of continents may by added by the editor
	if kind[word]['cat_super'] == '' and kind[word]['cat_super'] == nil then
		output = output
	elseif (super ~= '' and super ~= nil) and kind[word]['cat_super'] ~= '' and kind[word]['cat_super'] ~= nil then
		output = output .. '[[Κατηγορία:' .. kind[word]['word_cat'] .. ' ' .. where[super]['word_cat'] .. ' (' .. languages[lang_iso].name .. ')]]'
	end

-- ===================== kind cat_super + where cat_super ======================= --
-- ΣΥΝΔΥΑΣΜΟΣ COMBINATION kind cat_super true & where cat_super=
	-- test λίμνη - Ιταλία, [[Como]], αυτόματα + Λίμνες της Ευρώπης, χωρίς να χρειάζεται να το ζητήσει ο συντάκτης με παράμετρο |ηπ=
	if kind[word]['cat_super'] == true and where[area]['cat_super'] ~= '' and where[area]['cat_super'] ~= nil then
		output = output ..  '[[Κατηγορία:' .. kind[word]['word_cat'] .. ' ' ..  where[area]['cat_super'] .. ' (' .. languages[lang_iso].name .. ')]]'
-- test [[Alpi]]
	elseif kind[word]['cat_super'] == true and where[area]['cat_super'] == '' and where[area]['cat_super'] == nil then
		output = ouput
	end


end -- close nocat


return frame:preprocess(output)
end

return p