Module:lang
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]]
CONTENTS a...z
* WRITE apo, apota, cat, from, iso, name, words >> and GET some other parameter
* test with main function to [[Template:testing]]
]=]--
local p = {}
local languages = mw.loadData("Module:Languages")
-- error function
p.error = function(errorstring)
return '<span class="error">Δεν υπάρχει αυτός ο κωδικός γλώσσας!!</span> [[Κατηγορία:Σελίδες με σφάλμα στον κωδικό γλώσσας]]'
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 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 to make template
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 to make Template
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 a lang keyword-expression --
-- params from [[Module:Languages]]: apo apota/sta frm cat/searchcat name words
-- tests at [[Template:testing]]
----------------------------------------------------------------------------
-- apo (as in [[Module:Languages]] = feminine article + feminine singular, (e.g. την [[αγγλική]])
-- {{#invoke:lang|apo|{{{lang|{{{γλ|}}}}}}}} lang= ISO language code
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
-- ================================ iso to apota + sta
-- 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
-- apota (as in [[Module:Languages]] - expression like 'from English' - έκφραση όπως «από τα αγγλικά»
-- {{#invoke:lang|apota|{{{lang|{{{γλ|}}}}}}}} lang= ISO language code
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
-- make it στα... instead of από τα
-- {{#invoke:lang|sta|{{{lang|{{{γλ|}}}}}}}} lang= ISO language code
p.sta = 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 "στα νέα ελληνικά" end
if iso ~= '' then
if languages[iso] == nil then return p.error(errorstring)
-- it adds a number in the end. Isolate the terms between spaces
else
if mw.ustring.find(languages[iso].apota, '^από τ') then
return "" .. languages[iso].apota:gsub( "από τ", "στ" ) .. ""
elseif mw.ustring.find(languages[iso].apota, '^από ') then -- families of languages do not have article
return "" .. languages[iso].apota:gsub( "από ", "σε " ) .. ""
end
end
end
end
-- ================================ iso to cat & searchcat
-- write iso, get cat
-- if you need this function in another module, write:
-- xxxxx = require("Module:lang").langiso_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
-- cat (as in [[Module:Languages]]) = the name of the Category in Βικιλεξικό e.g. for iso = en > [[:Κατηγορία:Αγγλική γλώσσα]]
-- {{#invoke:lang|cat|{{{lang|{{{γλ|}}}}}}}} lang= ISO language code
p.cat = 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'].cat end
if iso ~= '' then
if languages[iso] == nil then return p.error(errorstring)
else return languages[iso].cat
end
end
end
-- at Searches, problem with space e.g. Αγγλική γλώσσα needs to be Αγγλική_γλώσσα
-- {{#invoke:lang|seachcat|{{{lang|{{{γλ|}}}}}}}} lang= ISO language code
p.searchcat = 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 'Νέα_ελληνικά' end
if iso ~= '' then
if languages[iso] == nil then return p.error(errorstring)
-- this returns e.g. Αγγλική_γλώσσα1 I do not know what 1 is. perhaps, the end of the word is perceived as space
-- else return languages[iso].cat:gsub( " ", "_" ) -- languages[iso].cat
-- then, DELETE last letter: oh no! it deletes the actual letter Αγγλική_γλώσσ
-- else return require("Module:stems").word_1(languages[iso].cat:gsub( " ", "_" ))
--make it isolated
else return "" .. languages[iso].cat:gsub( " ", "_" ) .. ""
end
end
end
-- ================================ iso to frm
-- frm (as in [[Module:Languages]] = feminine singular, (e.g. [[αγγλική]]) Όπως στο [[Πρότυπο:β]] για έκφραση 'αγγλική Βικιπαίδεια'
-- {{#invoke:lang|frm|{{{lang|{{{γλ|}}}}}}}} lang= ISO language code
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
-- ================================ iso to from
-- from (as in [[Module:Languages]] = phrase: feminine genitive singular + προέλευσης (origin)
-- (e.g. αγγλικής προέλευσης)
-- {{#invoke:lang|from|{{{lang|{{{γλ|}}}}}}}} lang= ISO language code
p.from = 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'].from end
if iso ~= '' then
if languages[iso] == nil then return p.error(errorstring)
else return languages[iso].from
end
end
end
-- ================================ iso to link & fixlink
-- write iso, get 'link'
-- if you need this function in another module, write:
-- xxxxx = require("Module:lang").langiso_to_langlink(xxxx)
function p.langiso_to_langlink(iso)
local ret = {}
local i = 1
local frm_to_char = {}
for _, v in pairs(require("Module:Languages")) do
local iso, frm, link = v.iso, v.frm, v.link
frm_to_char[frm] = link
if iso then -- this is need, otherwise it does not work (correction by Erutuon)
frm_to_char[iso:gsub("[%*%?]", "")] = link
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
-- link (as in [[Module:Languages]]) = the title of language at lemmata e.g. for iso = en > Αγγλικά (en)
-- {{#invoke:lang|cat|{{{lang|{{{γλ|}}}}}}}} lang= ISO language code
p.link = 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'].link end
if iso ~= '' then
if languages[iso] == nil then return p.error(errorstring)
else return languages[iso].link
end
end
end
-- at inner #links, problem with spaces e.g. Αγγλικά (en) needs to be Αγγλικά_(en)
-- {{#invoke:lang|fixlink|{{{lang|{{{γλ|}}}}}}}} lang= ISO language code
p.fixlink = 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 'Νέα_ελληνικά_(el)' end
if iso ~= '' then
if languages[iso] == nil then return p.error(errorstring)
else return "" .. languages[iso].link:gsub( " ", "_" ) .. ""
end
end
end
-- ================================ iso to name & searchname
-- name (as in [[Module:Languages]]) = neuter plural, lower case (e.g. [[αγγλικά]]), occasionally feminine singular (e.g. [[πρωτοϊνδοευρωπαϊκή]])
-- {{#invoke:lang|name|{{{lang|{{{γλ|}}}}}}}} lang= ISO language code
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
-- at Searches as in [[Template:list2]], problem with space e.g. αρχαία ελληνικά needs to be αρχαία_ελληνκικά
-- {{#invoke:lang|seachname|{{{lang|{{{γλ|}}}}}}}} lang= ISO language code
-- if you need to read the name in the Category title (parenthesis)
-- use [[Module:page]], function get_iso
-- and then, procede here
p.searchname = 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 'νέα_ελληνικά' end
if iso ~= '' then
if languages[iso] == nil then return p.error(errorstring)
--make it isolated
else return "" .. languages[iso].name:gsub( " ", "_" ) .. ""
end
end
end
-- ================================ iso to words
-- words (as in [[Module:Languages]] - expression like 'English words' - Αγγλικές λέξεις with capital first letter
-- {{#invoke:lang|words|{{{lang|{{{γλ|}}}}}}}} lang= ISO language code
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
-- ========================== for 'require' ============================ --
----------------------------------------------------------------------------
-- 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 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_langlink('grc') .. ' , '
.. 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