Module:lang >> Module:lang/τεκμηρίωση

Το Module παράγει στερεότυπες εκφράσεις για ονόματα γλωσσών όπως υπάρχουν στο Module:Languages.

Καλείται από Πρότυπα με {{#invoke:lang|<όνομα function>|<κωδικός iso γλώσσας>}}, όπως στο {{π-κατ}}, στο {{β}}


--[=[
Expressions - 2019.11.12. Sarri.greek
	Ονομασίες γλωσσών με εκφράσεις όπως υπάρχουν στο [[Module:Languages]]
	Καλείται από πρότυπα που χρησιμοποιούν πάγιες εκφράσεις που αφορούν γλώσσες. Tests at [[Module talk:lang]]
	ή με {{#invoke:lang|<function>|<language ISO>}}
	=
	Εxpressions for names of languages from [[Module:Languages]] in greek.
	Invoked by templates using standardized expressions for languages, or directly.  Tests at [[Module talk:lang]]
GetByKeyword: 2020.10.11 get by keywords: write name, get iso / write name, get key, etc
	* PROBLEM: ERROR warning or message., 
		It does not work when a field is empty in [[Module:Languages]]
]=]--

local p = {}

local languages = mw.loadData("Module:Languages")

-- error function
p.error = function(errorstring)
    return '<span class="error">Δεν υπάρχει αυτός ο κωδικός γλώσσας!!</span>'
end

----------------------------------------------------------------------------
--              write iso > get a lang keyword-expression                 --
----------------------------------------------------------------------------	

-- apota (as in [[Module:Languages]] - expression like 'from English' - έκφραση όπως «από τα αγγλικά»
p.apota = function(frame)
    local iso = frame.args[1] or frame:getParent().args[1] or ''
    if iso == nil then return p.error(errorstring) end
    if iso == '' then return languages['el'].apota end
    if iso ~= '' then
    	if languages[iso] == nil then return p.error(errorstring)
    		else return languages[iso].apota
    	end
    end
end


-- frm (as in [[Module:Languages]] = feminine singular, (e.g. [[αγγλική]]) Όπως στο [[Πρότυπο:β]] για έκφραση 'αγγλική Βικιπαίδεια'
p.frm = function(frame)
    local iso = frame.args[1] or frame:getParent().args[1] or ''
    if iso == nil then return p.error(errorstring) end
    if iso == '' then return languages['el'].frm end
    if iso ~= '' then
    	if languages[iso] == nil then return p.error(errorstring)
    		else return languages[iso].frm
    	end
    end
end


-- apo (as in [[Module:Languages]] = feminine article + feminine singular, (e.g. την [[αγγλική]])
p.apo = function(frame)
    local iso = frame.args[1] or frame:getParent().args[1] or ''
    if iso == nil then return p.error(errorstring) end
    if iso == '' then return languages['el'].apo end
    if iso ~= '' then
    	if languages[iso] == nil then return p.error(errorstring)
    		else return languages[iso].apo
    	end
    end
end

-- name (as in [[Module:Languages]]) = neuter plural, lower case (e.g. [[αγγλικά]]), occasionally feminine singular (e.g. [[πρωτοϊνδοευρωπαϊκή]])
p.name = function(frame)
    local iso = frame.args[1] or frame:getParent().args[1] or ''
    if iso == nil then return p.error(errorstring) end
    if iso == '' then return languages['el'].name end
    if iso ~= '' then 
    	if languages[iso] == nil then return p.error(errorstring)
    		else return languages[iso].name
    	end
    end
end

-- words (as in [[Module:Languages]] - expression like 'English words' - Αγγλικές λέξεις with capital first letter
p.words = function(frame)
    local iso = frame.args[1] or frame:getParent().args[1] or ''
    if iso == nil then return p.error(errorstring) end
    if iso == '' then return languages['el'].words end
    if iso ~= '' then
    	if languages[iso] == nil then return p.error(errorstring)
    		else return languages[iso].words
    	end
    end
end


----------------------------------------------------------------------------
--                    write name > get iso, key, etc                      --
----------------------------------------------------------------------------	

-- ================================ name to iso
-- write name, get iso
-- if you need this function in another module, write:
--			xxxxx = require("Module:lang").langname_to_langiso(xxxx)

function p.langname_to_langiso(name)
	local ret = {}
	local i = 1
	local frm_to_char = {}
		for _, v in pairs(require("Module:Languages")) do
			local name, frm, iso = v.name, v.frm, v.iso
			frm_to_char[frm] = iso
			frm_to_char[name:gsub("[%*%?]", "")] = iso
		end
	
	for c in mw.text.gsplit(name, "%.") do
		ret[i] = frm_to_char[c] or c
		i = i + 1
	end
	
	return table.concat(ret)
end

-- If I want to make a Template: NOT CHECKEDDDDDDDDDDDDDD
-- needed evern if you call p.langname_to_langiso
function p.name_to_iso(frame)
	local args = frame:getParent().args	-- only for Templates
--	local args = frame.args		-- only for direct invoke
    local text = args[1] or ""
--    if text == nil then return p.error(errorstring) end
    if args[1] == '' then text = 'νέα ελληνικά' end -- this is languages['el'].name
    if args[1] ~= '' then
    	if languages.name == nil then return p.error(errorstring)
    		else text = p.langname_to_langiso(text)
    	end
    end

	output = text

return output
end


----------------------------------------------------------------------------
--                         write apota > get ...                          --
----------------------------------------------------------------------------	

-- ================================ apota to iso
-- write apota, get iso
-- if you need this function in another module, write:
--			xxxxx = require("Module:lang").langapota_to_langiso(xxxx)

function p.langapota_to_langiso(apota)
	local ret = {}
	local i = 1
	local frm_to_char = {}
		for _, v in pairs(require("Module:Languages")) do
			local apota, frm, iso = v.apota, v.frm, v.iso
			frm_to_char[frm] = iso
			if apota then		-- this is need, otherwise it does not work (correction by Erutuon)
				frm_to_char[apota:gsub("[%*%?]", "")] = iso
			end
		end
	
	for c in mw.text.gsplit(apota, "%.") do
		ret[i] = frm_to_char[c] or c
		i = i + 1
	end
	
	return table.concat(ret)
end

-- NOT CHECKED
function p.apota_to_iso(frame)
	local args = frame:getParent().args	-- only for Templates
--	local args = frame.args		-- only for direct invoke
    local text = args[1] or ""
--    if text == nil then return p.error(errorstring) end
    if args[1] == '' then text = 'από τα νέα ελληνικά' end -- this is languages['el'].name
    if args[1] ~= '' then
    	if languages.apota == nil then return p.error(errorstring)
    		else text = p.langapota_to_langiso(text)
    	end
    end

	output = text

return output
end



-- ================================ apota to key
-- write apota, get key
-- if you need this function in another module, write:
--			xxxxx = require("Module:lang").langapota_to_langkey(xxxx)

function p.langapota_to_langkey(apota)
	local ret = {}
	local i = 1
	local frm_to_char = {}
		for _, v in pairs(require("Module:Languages")) do
			local apota, frm, key = v.apota, v.frm, v.key
			frm_to_char[frm] = key
			if apota then		-- this is need, otherwise it does not work (correction by Erutuon)
				frm_to_char[apota:gsub("[%*%?]", "")] = key
			end
		end
	
	for c in mw.text.gsplit(apota, "%.") do
		ret[i] = frm_to_char[c] or c
		i = i + 1
	end
	
	return table.concat(ret)
end

-- NOT CHECKED
-- if a template is desirable, make one with:
function p.apota_to_key(frame)
	local args = frame:getParent().args	-- only for Templates
--	local args = frame.args		-- only for direct invoke
    local text = args[1] or ""
--    if text == nil then return p.error(errorstring) end
    if args[1] == '' then text = 'από τα νέα ελληνικά' end -- this is languages['el'].apota
    if args[1] ~= '' then
    	if languages.apota == nil then return p.error(errorstring)
    		else text = p.langapota_to_langkey(text)
    	end
    end

	output = text

return output
end


----------------------------------------------------------------------------
--                          write cat > get...                            --
----------------------------------------------------------------------------	

-- ================================ cat to iso
-- write cat, get iso
-- if you need this function in another module, write:
--			xxxxx = require("Module:lang").langcat_to_langiso(xxxx)

function p.langcat_to_langiso(cat)
	local ret = {}
	local i = 1
	local frm_to_char = {}
		for _, v in pairs(require("Module:Languages")) do
			local cat, frm, iso = v.cat, v.frm, v.iso
			frm_to_char[frm] = iso
			if cat then		-- this is need, otherwise it does not work (correction by Erutuon)
				frm_to_char[cat:gsub("[%*%?]", "")] = iso
			end
		end
	
	for c in mw.text.gsplit(cat, "%.") do
		ret[i] = frm_to_char[c] or c
		i = i + 1
	end
	
	return table.concat(ret)
end

----------------------------------------------------------------------------
--                   write from (προέλευσης) > get ...                    --
----------------------------------------------------------------------------	

-- ================================ from to iso
-- write from, get iso
-- if you need this function in another module, write:
--			xxxxx = require("Module:lang").langfrom_to_langiso(xxxx)

function p.langfrom_to_langiso(from)
	local ret = {}
	local i = 1
	local frm_to_char = {}
		for _, v in pairs(require("Module:Languages")) do
			local from, frm, iso = v.from, v.frm, v.iso
			frm_to_char[frm] = iso
			if from then
				frm_to_char[from:gsub("[%*%?]", "")] = iso
			end
		end
	
	for c in mw.text.gsplit(from, "%.") do
		ret[i] = frm_to_char[c] or c
		i = i + 1
	end
	
	return table.concat(ret)
end

-- NOT CHECKED
function p.from_to_iso(frame)
	local args = frame:getParent().args	-- only for Templates
--	local args = frame.args		-- only for direct invoke
    local text = args[1] or ""
--    if text == nil then return p.error(errorstring) end
    if args[1] == '' then text = 'από τα νέα ελληνικά' end -- this is languages['el'].name
    if args[1] ~= '' then
    	if languages.from == nil then return p.error(errorstring)
    		else text = p.langfrom_to_langiso(text)
    	end
    end

	output = text

return output
end



-- ================================ from to key
-- write from, get key
-- if you need this function in another module, write:
--			xxxxx = require("Module:lang").langfrom_to_langkey(xxxx)

function p.langfrom_to_langkey(from)
	local ret = {}
	local i = 1
	local frm_to_char = {}
		for _, v in pairs(require("Module:Languages")) do
			local from, frm, key = v.from, v.frm, v.key
			frm_to_char[frm] = key
			if from then
				frm_to_char[from:gsub("[%*%?]", "")] = key
			end
		end
	
	for c in mw.text.gsplit(from, "%.") do
		ret[i] = frm_to_char[c] or c
		i = i + 1
	end
	
	return table.concat(ret)
end

-- NOT CHECKED
-- if a template is desirable, make one with:
function p.from_to_key(frame)
	local args = frame:getParent().args	-- only for Templates
--	local args = frame.args		-- only for direct invoke
    local text = args[1] or ""
--    if text == nil then return p.error(errorstring) end
    if args[1] == '' then text = 'από τα νέα ελληνικά' end -- this is languages['el'].apota
    if args[1] ~= '' then
    	if languages.apota == nil then return p.error(errorstring)
    		else text = p.langfrom_to_langkey(text)
    	end
    end

	output = text

return output
end


----------------------------------------------------------------------------
--                            write iso < get ...                        --
----------------------------------------------------------------------------	

-- ================================ iso to cat
-- write iso, get cat
-- if you need this function in another module, write:
--			xxxxx = require("Module:lang").laniso_to_langcat(xxxx)

function p.langiso_to_langcat(iso)
	local ret = {}
	local i = 1
	local frm_to_char = {}
		for _, v in pairs(require("Module:Languages")) do
			local iso, frm, cat = v.iso, v.frm, v.cat
			frm_to_char[frm] = cat
			if iso then		-- this is need, otherwise it does not work (correction by Erutuon)
				frm_to_char[iso:gsub("[%*%?]", "")] = cat
			end
		end
	
	for c in mw.text.gsplit(iso, "%.") do
		ret[i] = frm_to_char[c] or c
		i = i + 1
	end
	
	return table.concat(ret)
end


-- ================================ iso to apota
-- write iso, get apota
-- if you need this function in another module, write:
--			xxxxx = require("Module:lang").laniso_to_langapota(xxxx)

function p.langiso_to_langapota(iso)
	local ret = {}
	local i = 1
	local frm_to_char = {}
		for _, v in pairs(require("Module:Languages")) do
			local iso, frm, apota = v.iso, v.frm, v.apota
			frm_to_char[frm] = apota
			if iso then		-- this is need, otherwise it does not work (correction by Erutuon)
				frm_to_char[iso:gsub("[%*%?]", "")] = apota
			end
		end
	
	for c in mw.text.gsplit(iso, "%.") do
		ret[i] = frm_to_char[c] or c
		i = i + 1
	end
	
	return table.concat(ret)
end

----------------------------------------------------------------------------
--                   write apo (τη ...ή) > get ...                    --
----------------------------------------------------------------------------	

-- ================================ apo to iso
-- write apo, get iso
-- if you need this function in another module, write:
--			xxxxx = require("Module:lang").langapo_to_langiso(xxxx)

function p.langapo_to_langiso(apo)
	local ret = {}
	local i = 1
	local frm_to_char = {}
		for _, v in pairs(require("Module:Languages")) do
			local apo, frm, iso = v.apo, v.frm, v.iso
			frm_to_char[frm] = iso
			if apo then
				frm_to_char[apo:gsub("[%*%?]", "")] = iso
			end
		end
	
	for c in mw.text.gsplit(apo, "%.") do
		ret[i] = frm_to_char[c] or c
		i = i + 1
	end
	
	return table.concat(ret)
end

----------------------------------------------------------------------------
--                   write words (Λέξεις...) > get ...                    --
----------------------------------------------------------------------------	

-- ================================ words to iso
-- write words, get iso
-- if you need this function in another module, write:
--			xxxxx = require("Module:lang").langwords_to_langiso(xxxx)

function p.langwords_to_langiso(words)
	local ret = {}
	local i = 1
	local frm_to_char = {}
		for _, v in pairs(require("Module:Languages")) do
			local words, frm, iso = v.words, v.frm, v.iso
			frm_to_char[frm] = iso
			if words then
				frm_to_char[words:gsub("[%*%?]", "")] = iso
			end
		end
	
	for c in mw.text.gsplit(words, "%.") do
		ret[i] = frm_to_char[c] or c
		i = i + 1
	end
	
	return table.concat(ret)
end

-- NOT CHECKED
function p.words_to_iso(frame)
	local args = frame:getParent().args	-- only for Templates
--	local args = frame.args		-- only for direct invoke
    local text = args[1] or ""
--    if text == nil then return p.error(errorstring) end
    if args[1] == '' then text = 'από τα νέα ελληνικά' end -- this is languages['el'].name
    if args[1] ~= '' then
    	if languages.from == nil then return p.error(errorstring)
    		else text = p.langwords_to_langiso(text)
    	end
    end

	output = text

return output
end


-- ================================ words to name
-- write words, get name
-- if you need this function in another module, write:
--			xxxxx = require("Module:lang").langwords_to_langname(xxxx)

function p.langwords_to_langname(words)
	local ret = {}
	local i = 1
	local frm_to_char = {}
		for _, v in pairs(require("Module:Languages")) do
			local words, frm, name = v.words, v.frm, v.name
			frm_to_char[frm] = name
			if words then
				frm_to_char[words:gsub("[%*%?]", "")] = name
			end
		end
	
	for c in mw.text.gsplit(words, "%.") do
		ret[i] = frm_to_char[c] or c
		i = i + 1
	end
	
	return table.concat(ret)
end

-- Test at [[Template:words_to_name]]
function p.words_to_name(frame)
	local args = frame:getParent().args	-- only for Templates
--	local args = frame.args		-- only for direct invoke
    local text = args[1] or ""
--    if text == nil then return p.error(errorstring) end
    if args[1] == '' then text = 'από τα νέα ελληνικά' end -- this is languages['el'].name

-- PROBLEM:
--    if args[1] ~= '' then
--    	if languages.from == nil then return p.error(errorstring)
--   		else text = p.langwords_to_langname(text)
--    	end
--    end

	text = p.langwords_to_langname(text)
	
	output = text

return output
end

----------------------------------------------------------------------------
--                        TESTS with function main                      --
----------------------------------------------------------------------------	
function p.main(frame) -- check at [[Template:testing]]
--	local args = frame:getParent().args	-- for Templates
--	local args = frame.args		-- invoke
--	local arg1 = frame.args[1] or frame:getParent().args[1] or ''  -- for BOTH

	output = 'output is '
--  error message for wrong name, does not work

		.. p.langname_to_langiso('αγγλικά') .. ' ,  '
		.. p.langname_to_langiso('νέα ελληνικά') .. ' ,  '
		.. p.langname_to_langiso('blabla') .. ' ,  <br> ' -- this gives blabla is a PROBLEM: IT SHOULD GIVE MESSAGE: there is no such code
-- from iso
		.. p.langiso_to_langapota('ru') .. ' , <br> '
-- from apota
		.. p.langapota_to_langkey('από τα αγγλικά') .. ' ,  '
		.. p.langapota_to_langkey('απόταδδδ') .. ' ,  ' -- get error here
		.. p.langapota_to_langiso('από τα αγγλικά') .. ' ,  '
		.. p.langapota_to_langiso('απόταδδδ') .. ' , <br> ' -- get error here
-- from cat e.g. [[:Κατηγορία:Αγγλική γλώσσα]]
		.. p.langcat_to_langiso('Αγγλική γλώσσα') .. ' ,  ' -- writes: en
		.. p.langcat_to_langiso('ΧΧΧΧΧ') .. ' , <br> ' -- it writes: XXXX
-- from 'from'
		.. p.langfrom_to_langiso('αρχαίας ελληνικής προέλευσης') .. ' ,  '
		.. p.langfrom_to_langkey('νεοελληνικής προέλευσης') .. ' ,<br>  '
-- from apo
		.. p.langapo_to_langiso('την αραβική') .. ' , <br> '
-- from words
		.. p.langwords_to_langiso('Ιταλικές λέξεις') .. ' ,  '
		.. p.langwords_to_langiso('Λέξεις της γλώσσας αφρικάανς') .. ' ,  '
		.. p.langwords_to_langname('Ιταλικές λέξεις') .. ' ,  '
		.. p.langwords_to_langname('Λέξεις της γλώσσας αφρικάανς') .. ' , <br> '


return output
end -- end function main




return p