Module:Linb-translit

Από Βικιλεξικό
Μετάβαση στην πλοήγηση Πήδηση στην αναζήτηση

Module:Linb-translit >> Module:Linb-translit/data   << Module:Linb-translit/tests   << Module:Linb-translit/τεκμηρίωση
Module:Linb-translit >> Module:Linb-translit/uniToTranslit
Module:Linb-translit >> Module:Linb-translit/uniToImg
Δημιουργεί πρότυπα μεταγραφής για τη Γραμμική Β, τη γραφή της μυκηναϊκής διαλέκτου (Κατηγορία:Μυκηναϊκή διάλεκτος).

  • πρότυπο {{gmy-tr}}   (από τα Unicode σύμβολα λαμβάνουμε link & τη διεθνή μεταγραφή σε παρένθεση)
  • πρότυπο {{gmy-translit}}   (από τα Unicode σύμβολα λαμβάνουμε πίνακα με τη διεθνή μεταγραφή και τις εικόνες των χαρακτήρων, καθώς τα Unicode δεν είναι πάντα ορατά σε όλους)
  • πρότυπο {{gmy-link}}   (από τη διεθνή μεταγραφή με λατινικά γράμματα, που θυμόμαστε εύκολα, λαμβάνουμε link & τα σύμβολα Unicode)
  • invoke gmy_get   (από τη μεταγραφή λαμβάνουμε απλώς τα Unicode σύμβολα)
  • πρότυπο {{gmy-image}}   (από τη διεθνή μεταγραφή, λαμβάνουμε εικόνες χαρακτήρων: γράφουμε ό,τι θέλουμε!)

--[=[
2020.08.19. Sarri.greek - Last update:2020.11.19.
	Λειτουργίες για τη μυκηναϊκή διάλεκτο: μεταγραφές της Γραμμικής Β
	Ο πίνακας με τις εικόνες δημιουργήθηκε διότι σε πολλούς browsers οι χαρακτήρες Unicode δεν είναι ορατοί.
	[[Πρότυπο:gmy-translit]] (για τον πίνακα) - [[Πρότυπο:gmy-tr]] (η διεθνής μεταγραφή για γραμμή λήμματος)
	Functions for Mycenaean dialect: transliterations of Linear B
STRUCTURE
	requirements
	1) unicode to latin transliteration with link
		tr - [[Πρότυπο:gmy-tr]] έχουμε τα σύμβολα, παίρνουμε μεταγραφή εντός παρένθεσης, με link στα σύμβολα, ή στο pagename χωρίς Link
	2) unicode to latin+image box
		σχέδιο κουτιού - the box
		translit - [[Πρότυπο:gmy-translit]] έχουμε τα σύμβολα, παίρνουμε κουτί με τη διεθνή μεταγραφή + εικόνες χαρακτήρων
	3) gmy_link: from latin translit get unicode link + translit
	4) gmy_get: from latin translit get unicode
	5) gmy_image: from latin translit, get images
SOURCES
	[[:en:User:Erutuon]] Τhank you Erutuon, for your help!
	https://en.wiktionary.org/wiki/Module:Linb-translit
	https://en.wikipedia.org/wiki/Linear_B
PROBLEMS
	* The translit box is possible only up to 7 characters. 
2020.08.22. Last update

]=]--


local export = {}

local module_path = 'Module:Linb-translit'

local m_data = mw.loadData("Module:Linb-translit/data") -- latin translit, image, Bennett code numbers, unicode symbol

-- subdata: partial lists from data
local m_uniToTranslit = mw.loadData("Module:Linb-translit/uniToTranslit")
local m_uniToImg = mw.loadData("Module:Linb-translit/uniToImg")
local m_translitToUni = mw.loadData("Module:Linb-translit/translitToUni") -- not needed


--------------------------------------------------------------------------
--                       [[Πρότυπο:gmy-tr]]                             --            
--            από σύμβολα, μεταγραφή σε παρένθεση και link              --
--      unicode symbol to latin transliteration in parenthesis          --
--------------------------------------------------------------------------

-- ============ convert unicode symbols to latin transliteration
-- from 2020.08. https://en.wiktionary.org/wiki/Module:Linb-translit
function export.uni_to_latin(text)
	local ret = {}
	local i = 1
	
	for c in string.gmatch(text, "[%z\1-\127\194-\244][\128-\191]*") do -- UTF-8 character pattern = (text, ".") = text, every character
			-- test: withdraw "[%z\1-\127\194-\244][\128-\191]*", use "." See Talk page
			-- NO, DO NOT USE "." it destroys everything
		ret[i] = m_uniToTranslit.chars[c] or c
		i = i + 1
	end
	
	text = string.gsub(table.concat(ret, "-"), "%- %-", " ")
	text = string.gsub(text, "%-?`%-?", "-")
	
	return text
end
--------------------------------------------------------------------------
-- [[Πρότυπο:gmy-tr]] unicode to transliteration
-- auto από PAGENAME, και με παράμετρο λήμμα= ή lemma=
-- =======================================================
export.tr = function(frame)
	local args = frame:getParent().args	-- for Templates
--	local args = frame.args		-- invoke
    local lemma = ""
    local text = args[1] or ""

    if args['λήμμα'] ~= nil and args['λήμμα'] ~= "" then
        lemma = args['λήμμα']
 elseif args['lemma'] ~= nil and args['lemma'] ~= "" then
        lemma = args['lemma']  
 elseif args[1] ~= nil and args[1] ~= "" then
        lemma = args[1]     
    else
        PAGENAME = mw.title.getCurrentTitle().text
        lemma = PAGENAME:match( "^%s*(.-)%s*$" ) -- αφαιρεί κάτι κενά στην αρχή και στο τέλος - υπάρχει σε όλα τα Modules
	end

	if args[1] ~= '' and args[1] ~= nil  then
		output = "[[" .. text .. "]] " .. '(<span title="η μεταγραφή των χαρακτήρων δεν αντιστοιχεί ακριβώς στην προφορά">' .. export.uni_to_latin(lemma) .. "</span>)"
	else
		output = '(<span title="η μεταγραφή των χαρακτήρων δεν αντιστοιχεί ακριβώς στην προφορά">' .. export.uni_to_latin(lemma) .. "</span>)"
--	else
--		text = "Κάπου υπάρχει λάθος!"
	end

return output
end


--------------------------------------------------------------------------
--                       [[Πρότυπο:gmy-translit]]                       --
--       από unicode σύμβολα παίρνω μεταγραφή & εικόνες σε ΚΟΥΤΙ        --
--         form unicdoe, get transliteration & images in a BOX          --
--------------------------------------------------------------------------
-- (unicode of Linear B are not visible in most browsers)
-- maximum: 7 symbols


-- ============    ΚΟΥΤΙ / the BOX
fulltable = function(args)
	local row1str = ''
	local row2str = ''
	local letter = args['gmy-lat'] or ''
	local symbol = args['gmy-img'] or ''
	local no_float = args['nofloat'] or ''

-- add this to detailed columns, not possible here: | style="text-align:center; font-weight:bold;"  align="center" | 
	row1str = [=[|  ]=] .. args['gmy-lat'] .. "\n"
	row2str = [=[|  ]=] .. args['gmy-img'] .. "\n"

-- the box: rows Careful: have to change line after <div...>
	if args['nofloat'] == '1' then
	output =  [=[
{| style="background:#f4f4f4;" rules="rows"
|-
	| ]=] .. row1str .. [=[|-
	| ]=] .. row2str .. [=[|}]=]

	else -- it floats right
		
	output = [=[<div style="float:right;">
{| style="background:#f4f4f4;" rules="rows"
|-
	| ]=] .. row1str .. [=[|-
	| ]=] .. row2str .. [=[|}
</div>]=]
		
	end
return output -- close fulltable
end

-- ============ convert unicode symbols to images -- by [[User:Flyax|Flyax]], at [[Module:grc-nouns-decl]]
function export.uni_to_img(symbol)
    stempoint = mw.ustring.len(symbol)
    wordproduced = ""
    while stempoint > 0 do
       mychar = mw.ustring.sub(symbol, stempoint, stempoint)
       newchar = m_uniToImg.img[mychar]
       if newchar ~= nil then
          if stempoint > 1 then
              return mw.ustring.sub(symbol, 1, stempoint-1 ) .. newchar .. wordproduced
          else
              return newchar .. wordproduced
          end
       else
           wordproduced = mychar .. wordproduced
           stempoint = stempoint -1
       end
    end
    return wordproduced
end

--------------------------------------------------------------------------
-- [[Πρότυπο:gmy-translit]] για έως και 7 συλλαβές
-- auto από PAGENAME, και με παράμετρο λήμμα= ή lemma=
-- =======================================================
export.translit = function(frame)
	local args = frame:getParent().args	-- for Templates
--	local args = frame.args		-- invoke
    local lemma = ""

    if args['λήμμα'] ~= nil and args['λήμμα'] ~= "" then
        lemma = args['λήμμα']
elseif args['lemma'] ~= nil and args['lemma'] ~= "" then
        lemma = args['lemma']
elseif args[1] ~= nil and args[1] ~= "" then
        lemma = args[1]
    else
        PAGENAME = mw.title.getCurrentTitle().text
        lemma = PAGENAME:match( "^%s*(.-)%s*$" ) -- αφαιρεί κάτι κενά στην αρχή και στο τέλος - υπάρχει σε όλα τα Modules
    end
    local stemnumber = tonumber(mw.ustring.len(lemma))
	local letter = args['gmy-lat'] or ''
	local symbol = args['gmy-img'] or ''
	
-- cannot do style=.... at the first TD
	if stemnumber == 1 then
		args['gmy-lat'] = "<center><b>" .. export.uni_to_latin(mw.ustring.sub(lemma,1,1)) .. "</b></center>"
		args['gmy-img'] = "<center>" .. export.uni_to_img(mw.ustring.sub(lemma,1,1)) .. "</center>"
	elseif stemnumber == 2 then
		args['gmy-lat'] = "<center><b>" .. export.uni_to_latin(mw.ustring.sub(lemma,1,1)) .. "</b></center>" ..
		[=[ || style="text-align:center; font-weight:bold;" align="center" | ]=] .. export.uni_to_latin(mw.ustring.sub(lemma,2,2))
		args['gmy-img'] = "<center>" .. export.uni_to_img(mw.ustring.sub(lemma,1,1)) .. "</center>" ..
		[=[ || style="text-align:center;" align="center" | ]=] .. export.uni_to_img(mw.ustring.sub(lemma,2,2))
	elseif stemnumber == 3 then
		args['gmy-lat'] = "<center><b>" .. export.uni_to_latin(mw.ustring.sub(lemma,1,1)) .. "</b></center>" ..
		[=[ || style="text-align:center; font-weight:bold;" align="center" | ]=] .. export.uni_to_latin(mw.ustring.sub(lemma,2,2)) .. 
		[=[ || style="text-align:center; font-weight:bold;" align="center" | ]=] .. export.uni_to_latin(mw.ustring.sub(lemma,3,3))
		args['gmy-img'] = "<center>" .. export.uni_to_img(mw.ustring.sub(lemma,1,1)) .. "</center>" ..
		[=[ || style="text-align:center;" align="center" | ]=] .. export.uni_to_img(mw.ustring.sub(lemma,2,2)) ..  
		[=[ || style="text-align:center;" align="center" | ]=] .. export.uni_to_img(mw.ustring.sub(lemma,3,3))
	elseif stemnumber == 4 then
		args['gmy-lat'] = "<center><b>" .. export.uni_to_latin(mw.ustring.sub(lemma,1,1)) .. "</b></center>" ..
		[=[ || style="text-align:center; font-weight:bold;" align="center" | ]=] .. export.uni_to_latin(mw.ustring.sub(lemma,2,2)) .. 
		[=[ || style="text-align:center; font-weight:bold;" align="center" | ]=] .. export.uni_to_latin(mw.ustring.sub(lemma,3,3)) .. 
		[=[ || style="text-align:center; font-weight:bold;" align="center" | ]=] .. export.uni_to_latin(mw.ustring.sub(lemma,4,4))
		args['gmy-img'] = "<center>" .. export.uni_to_img(mw.ustring.sub(lemma,1,1)) .. "</center>" ..
		[=[ || style="text-align:center;" align="center" | ]=] .. export.uni_to_img(mw.ustring.sub(lemma,2,2)) ..  
		[=[ || style="text-align:center;" align="center" | ]=] .. export.uni_to_img(mw.ustring.sub(lemma,3,3)) ..  
		[=[ || style="text-align:center;" align="center" | ]=] .. export.uni_to_img(mw.ustring.sub(lemma,4,4))
	elseif stemnumber == 5 then
		args['gmy-lat'] = "<center><b>" .. export.uni_to_latin(mw.ustring.sub(lemma,1,1)) .. "</b></center>" ..
		[=[ || style="text-align:center; font-weight:bold;" align="center" | ]=] .. export.uni_to_latin(mw.ustring.sub(lemma,2,2)) .. 
		[=[ || style="text-align:center; font-weight:bold;" align="center" | ]=] .. export.uni_to_latin(mw.ustring.sub(lemma,3,3)) .. 
		[=[ || style="text-align:center; font-weight:bold;" align="center" | ]=] .. export.uni_to_latin(mw.ustring.sub(lemma,4,4)) .. 
		[=[ || style="text-align:center; font-weight:bold;" align="center" | ]=] .. export.uni_to_latin(mw.ustring.sub(lemma,5,5))
		args['gmy-img'] = "<center>" .. export.uni_to_img(mw.ustring.sub(lemma,1,1)) .. "</center>" ..
		[=[ || style="text-align:center;" align="center" | ]=] .. export.uni_to_img(mw.ustring.sub(lemma,2,2)) ..  
		[=[ || style="text-align:center;" align="center" | ]=] .. export.uni_to_img(mw.ustring.sub(lemma,3,3)) ..  
		[=[ || style="text-align:center;" align="center" | ]=] .. export.uni_to_img(mw.ustring.sub(lemma,4,4)) ..  
		[=[ || style="text-align:center;" align="center" | ]=] .. export.uni_to_img(mw.ustring.sub(lemma,5,5))	
	elseif stemnumber == 6 then
		args['gmy-lat'] = "<center><b>" .. export.uni_to_latin(mw.ustring.sub(lemma,1,1)) .. "</b></center>" ..
		[=[ || style="text-align:center; font-weight:bold;" align="center" | ]=] .. export.uni_to_latin(mw.ustring.sub(lemma,2,2)) .. 
		[=[ || style="text-align:center; font-weight:bold;" align="center" | ]=] .. export.uni_to_latin(mw.ustring.sub(lemma,3,3)) .. 
		[=[ || style="text-align:center; font-weight:bold;" align="center" | ]=] .. export.uni_to_latin(mw.ustring.sub(lemma,4,4)) .. 
		[=[ || style="text-align:center; font-weight:bold;" align="center" | ]=] .. export.uni_to_latin(mw.ustring.sub(lemma,5,5)) .. 
		[=[ || style="text-align:center; font-weight:bold;" align="center" | ]=] .. export.uni_to_latin(mw.ustring.sub(lemma,6,6))
		args['gmy-img'] = "<center>" .. export.uni_to_img(mw.ustring.sub(lemma,1,1)) .. "</center>" ..
		[=[ || style="text-align:center;" align="center" | ]=] .. export.uni_to_img(mw.ustring.sub(lemma,2,2)) ..  
		[=[ || style="text-align:center;" align="center" | ]=] .. export.uni_to_img(mw.ustring.sub(lemma,3,3)) ..  
		[=[ || style="text-align:center;" align="center" | ]=] .. export.uni_to_img(mw.ustring.sub(lemma,4,4)) .. 
		[=[ || style="text-align:center;" align="center" | ]=] .. export.uni_to_img(mw.ustring.sub(lemma,5,5)) ..  
		[=[ || style="text-align:center;" align="center" | ]=] .. export.uni_to_img(mw.ustring.sub(lemma,6,6))
-- have not found a 7-syllable word, but just in case:
	elseif stemnumber == 7 then
		args['gmy-lat'] = "<center><b>" .. export.uni_to_latin(mw.ustring.sub(lemma,1,1)) .. "</b></center>" ..
		[=[ || style="text-align:center; font-weight:bold;" align="center" | ]=] .. export.uni_to_latin(mw.ustring.sub(lemma,2,2)) .. 
		[=[ || style="text-align:center; font-weight:bold;" align="center" | ]=] .. export.uni_to_latin(mw.ustring.sub(lemma,3,3)) .. 
		[=[ || style="text-align:center; font-weight:bold;" align="center" | ]=] .. export.uni_to_latin(mw.ustring.sub(lemma,4,4)) .. 
		[=[ || style="text-align:center; font-weight:bold;" align="center" | ]=] .. export.uni_to_latin(mw.ustring.sub(lemma,5,5)) .. 
		[=[ || style="text-align:center; font-weight:bold;" align="center" | ]=] .. export.uni_to_latin(mw.ustring.sub(lemma,6,6)) .. 
		[=[ || style="text-align:center; font-weight:bold;" align="center" | ]=] .. export.uni_to_latin(mw.ustring.sub(lemma,7,7))
		args['gmy-img'] = "<center>" .. export.uni_to_img(mw.ustring.sub(lemma,1,1)) .. "</center>" ..
		[=[ || style="text-align:center;" align="center" | ]=] .. export.uni_to_img(mw.ustring.sub(lemma,2,2)) ..  
		[=[ || style="text-align:center;" align="center" | ]=] .. export.uni_to_img(mw.ustring.sub(lemma,3,3)) ..  
		[=[ || style="text-align:center;" align="center" | ]=] .. export.uni_to_img(mw.ustring.sub(lemma,4,4)) .. 
		[=[ || style="text-align:center;" align="center" | ]=] .. export.uni_to_img(mw.ustring.sub(lemma,5,5)) .. 
		[=[ || style="text-align:center;" align="center" | ]=] .. export.uni_to_img(mw.ustring.sub(lemma,6,6)) .. 
		[=[ || style="text-align:center;" align="center" | ]=] .. export.uni_to_img(mw.ustring.sub(lemma,7,7))
	
	else
		return '<span style="color:#b22222; font-size:13pt;">Υπάρχει κάποιο λάθος!</span>'
	end
return fulltable(args)
end


--------------------------------------------------------------------------
--                       [[Πρότυπο:gmy-link]]                            --            
--         από τη λατινική μεταγραφή λαμβάνουμε unicode σύμβολα         --
--          from latin transliteration we get the unicode symbols        --
--------------------------------------------------------------------------

-- ============ convert latin transliteration to unicode symbols - by Erutuon
-- by Erutuon: how to use the /data page instead of subpages

function export.latin_to_uni(latin)
	local ret = {}
	local i = 1
	local code_to_char = {}
		for _, v in pairs(require("Module:Linb-translit/data")) do
			local latin, code, uni = v.latin, v.code, v.uni
			code_to_char[code] = uni
			code_to_char[latin:gsub("[%*%?]", "")] = uni
		end

	for c in mw.text.gsplit(latin, "%-") do    -- NOT string.gmatch(text, ".") do
		ret[i] = code_to_char[c] or c
		i = i + 1
	end
	
	return table.concat(ret)
end

--------------------------------------------------------------------------
-- [[Πρότυπο:gmy-link]] 
-- from latin transliteration get unicode: link (translit)
export.gmy_link = function(frame)
	local args = frame:getParent().args	-- for Templates
--	local args = frame.args		-- invoke
    local lemma = ""
    local text = args[1] or ""

    if args['λήμμα'] ~= nil and args['λήμμα'] ~= "" then
        lemma = args['λήμμα']
 elseif args['lemma'] ~= nil and args['lemma'] ~= "" then
        lemma = args['lemma']  
 elseif args[1] ~= nil and args[1] ~= "" then
        lemma = args[1]     
    else
        PAGENAME = mw.title.getCurrentTitle().text
        lemma = PAGENAME:match( "^%s*(.-)%s*$" ) -- αφαιρεί κάτι κενά στην αρχή και στο τέλος - υπάρχει σε όλα τα Modules
	end

	if args[1] ~= '' and args[1] ~= nil  then
		output = "[[" .. export.latin_to_uni(lemma) .. "]] " .. "(" .. text .. ")"
	else
		output = lemma .. ": [[" .. export.latin_to_uni(lemma) .. "]]"
--	else
--		text = "Κάπου υπάρχει λάθος!"
	end

return output
end

--------------------------------------------------------------------------
-- gmy-get
-- simple conversion: from latin transliteration write the unicode symbols
export.gmy_get = function(arg)
	local term
	if type(arg) == 'table' and type(arg.getParent) == 'function' then
		local frame = arg
		local args = frame:getParent().args
		term = args[1] or ''
	else
		term = arg
	end
	
--	local args = frame:getParent().args	-- for Templates
--	local args = frame.args		-- invoke
--	local args = frame.args[1] or frame:getParent().args[1] or ''  -- for BOTH
				-- CAREFUL: placing « or '' » before frame...args, does not work. It has to be in the end
--	local latin = args[1] or ''

--	if args[1] ~= nil and args[1] ~= "" then
		output = export.latin_to_uni(term)
--	end

return output
end


--------------------------------------------------------------------------
--                      [[Πρότυπο:gmy-image]]                           --            
--            από τη μεταγραφή λαμβάνουμε εικόνες χαρακτήρων            --
--               from latin transliteration we get images               --
--------------------------------------------------------------------------
-- ======================= translit to image
function export.latin_to_img(latin)
	local ret = {}
	local i = 1
	local code_to_char = {}
		for _, v in pairs(require("Module:Linb-translit/data")) do
			local latin, code, img = v.latin, v.code, v.img
			code_to_char[code] = img
			code_to_char[latin:gsub("[%*%?]", "")] = img
		end

	for c in mw.text.gsplit(latin, "%-") do    -- NOT string.gmatch(text, ".") do
		ret[i] = code_to_char[c] or c
		i = i + 1
	end
	
	return table.concat(ret)
end

-- [[Πρότυπο:gmy-image]] 
-- from latin transliteration get images
export.gmy_image = function(frame)
	local args = frame:getParent().args	-- for Templates
--	local args = frame.args		-- invoke
    local lemma = ""
    local text = args[1] or ""

-- if args[1] ~= nil and args[1] ~= "" then

 output = '<span title="η μεταγραφή των χαρακτήρων δεν αντιστοιχεί ακριβώς στην προφορά">' .. text .. '</span>' .. export.latin_to_img(text) 

return output
end

return export