Module:Linb-translit

Hello, you have come here looking for the meaning of the word Module:Linb-translit. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:Linb-translit, but we will also tell you about its etymology, its characteristics and you will know how to say Module:Linb-translit in singular and plural. Everything you need to know about the word Module:Linb-translit you have here. The definition of the word Module:Linb-translit will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:Linb-translit, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

This module will transliterate text in the Linear B script. It is used to transliterate Mycenaean Greek. The module should preferably not be called directly from templates or other modules. To use it from a template, use {{xlit}}. Within a module, use Module:languages#Language:transliterate.

For testcases, see Module:Linb-translit/testcases.

Functions

tr(text, lang, sc)
Transliterates a given piece of text written in the script specified by the code sc, and language specified by the code lang.
When the transliteration fails, returns nil.

-- In the |subst= parameter, as there is not a better way, use @ to force ideogram
-- reading for ambiguous characters, and use + to indicate superimposition.

local export = {}

local gsub = mw.ustring.gsub

-- Special character to ignore formatting in replacements. Only one character
-- because bolding should be ignored, but tables shouldn't.
local format_char = "?"
local spec_char = "%{%}⟦⟧⟨⟩/]?" .. format_char

local dig_chars = {
	 = 0,
	 = 1,
	 = 2,
	 = 3,
	 = 4,
	 = 5,
	 = 6,
	 = 7,
	 = 8,
	 = 9,
	 = 10,
	 = 20,
	 = 30,
	 = 40,
	 = 50,
	 = 60,
	 = 70,
	 = 80,
	 = 90,
	 = 100,
	 = 200,
	 = 300,
	 = 400,
	 = 500,
	 = 600,
	 = 700,
	 = 800,
	 = 900,
	 = 1000,
	 = 2000,
	 = 3000,
	 = 4000,
	 = 5000,
	 = 6000,
	 = 7000,
	 = 8000,
	 = 9000,
	 = 10000,
	 = 20000,
	 = 30000,
	 = 40000,
	 = 50000,
	 = 60000,
	 = 70000,
	 = 80000,
	 = 90000,
}

local chars = {
	-- SYLLABOGRAMS --
	 = { id = "1", tl = "da" },
	 = { id = "2", tl = "ro" },
	 = { id = "3", tl = "pa" },
	 = { id = "4", tl = "te" },
	 = { id = "5", tl = "to" },
	 = { id = "6", tl = "na" },
	 = { id = "7", tl = "di" },
	 = { id = "8", tl = "a" },
	 = { id = "9", tl = "se" },
	 = { id = "10", tl = "u" },
	 = { id = "11", tl = "po" },
	 = { id = "12", tl = "so" },
	 = { id = "13", tl = "me" },
	 = { id = "14", tl = "do" },
	 = { id = "15", tl = "mo" },
	 = { id = "16", tl = "qa" },
	 = { id = "17", tl = "za" },
	 = { id = "18" },
	 = { id = "19" },
	 = { id = "20", tl = "zo" },
	 = { id = "21", tl = "qi" },
	 = { id = "22" },
	 = { id = "23", tl = "mu" },
	 = { id = "24", tl = "ne" },
	 = { id = "25", tl = "a2" },
	 = { id = "26", tl = "ru" },
	 = { id = "27", tl = "re" },
	 = { id = "28", tl = "i" },
	 = { id = "29", tl = "pu2" },
	 = { id = "30", tl = "ni" },
	 = { id = "31", tl = "sa" },
	 = { id = "32", tl = "qo" },
	 = { id = "33", tl = "ra3" },
	 = { id = "34" },
	-- *35 is a flipped variant of *34
	 = { id = "36", tl = "jo" },
	 = { id = "37", tl = "ti" },
	 = { id = "38", tl = "e" },
	 = { id = "39", tl = "pi" },
	 = { id = "40", tl = "wi" },
	 = { id = "41", tl = "si" },
	 = { id = "42", tl = "wo" },
	 = { id = "43", tl = "a3" },
	 = { id = "44", tl = "ke" },
	 = { id = "45", tl = "de" },
	 = { id = "46", tl = "je" },
	 = { id = "47" },
	 = { id = "48", tl = "nwa" },
	 = { id = "49" },
	 = { id = "50", tl = "pu" },
	 = { id = "51", tl = "du" },
	 = { id = "52", tl = "no" },
	 = { id = "53", tl = "ri" },
	 = { id = "54", tl = "wa" },
	 = { id = "55", tl = "nu" },
	 = { id = "56" },
	 = { id = "57", tl = "ja" },
	 = { id = "58", tl = "su" },
	 = { id = "59", tl = "ta" },
	 = { id = "60", tl = "ra" },
	 = { id = "61", tl = "o" },
	 = { id = "62", tl = "pte" },
	 = { id = "63" },
	 = { id = "64" },
	 = { id = "65", tl = "ju" },
	 = { id = "66", tl = "ta2" },
	 = { id = "67", tl = "ki" },
	 = { id = "68", tl = "ro2" },
	 = { id = "69", tl = "tu" },
	 = { id = "70", tl = "ko" },
	 = { id = "71", tl = "dwe" },
	 = { id = "72", tl = "pe" },
	 = { id = "73", tl = "mi" },
	 = { id = "74", tl = "ze" },
	 = { id = "75", tl = "we" },
	 = { id = "76", tl = "ra2" },
	 = { id = "77", tl = "ka" },
	 = { id = "78", tl = "qe" },
	 = { id = "79" },
	 = { id = "80", tl = "ma" },
	 = { id = "81", tl = "ku" },
	 = { id = "82" },
	 = { id = "83" },
	-- *84
	 = { id = "85", tl = "au" },
	 = { id = "86" },
	 = { id = "87", tl = "twe" },
	-- *88
	 = { id = "89" },
	 = { id = "90", tl = "dwo" },
	 = { id = "91", tl = "two" },
	-- IDEOGRAMS --
	 = { id = "100", tl = "VIR" },
	-- *101 is a variant of *100
	 = { id = "102", tl = "MUL" },
	-- *103 is a variant of *102
	 = { id = "104", tl = "CERV" },
	 = { id = "105", tl = "EQU" },
	 = { id = "105f", tl = "EQU<sup>f</sup>" },
	 = { id = "105m", tl = "EQU<sup>m</sup>" },
	 = { id = "106", tl = "OVIS" }, -- same as *21
	 = { id = "106f", tl = "OVIS<sup>f</sup>" },
	 = { id = "106m", tl = "OVIS<sup>m</sup>" },
	 = { id = "107", tl = "CAP" }, -- same as *22
	 = { id = "107f", tl = "CAP<sup>f</sup>" },
	 = { id = "107m", tl = "CAP<sup>m</sup>" },
	 = { id = "108", tl = "SUS" }, -- same as *85
	 = { id = "108f", tl = "SUS<sup>f</sup>" },
	 = { id = "108m", tl = "SUS<sup>m</sup>" },
	 = { id = "109", tl = "BOS" }, -- same as *23
	 = { id = "109f", tl = "BOS<sup>f</sup>" },
	 = { id = "109m", tl = "BOS<sup>m</sup>" },
	 = { id = "110", tl = "Z" },
	 = { id = "111", tl = "V" },
	 = { id = "112", tl = "T" },
	 = { id = "113", tl = "S" },
	 = { id = "114", tl = "Q" },
	 = { id = "115", tl = "P" },
	 = { id = "116", tl = "N" },
	 = { id = "117", tl = "M" },
	 = { id = "118", tl = "L" },
	 = { id = "120", tl = "GRA" },
	 = { id = "121", tl = "HORD" },
	 = { id = "122", tl = "OLIV" },
	 = { id = "123", tl = "AROM" },
	-- *124 is a flipped variant of *125, traditionally transliterated as PYC
	 = { id = "125", tl = "CYP" },
	-- *126
	 = { id = "127", tl = "ka+po" },
	 = { id = "128", tl = "ka+na+ko" },
	 = { id = "129", tl = "FAR" }, -- same as *65
	 = { id = "130", tl = "OLE" },
	 = { id = "131", tl = "VIN" },
	 = { id = "132" },
	 = { id = "133", tl = "a+re+pa" },
	-- *134
	 = { id = "135", tl = "me+ri", },
	 = { id = "140", tl = "AES" },
	 = { id = "141", tl = "AUR" },
	 = { id = "142" },
	-- *143
	 = { id = "144", tl = "CROC" },
	 = { id = "145", tl = "LANA" },
	 = { id = "146" },
	-- *147, *148, *149
	 = { id = "150" },
	 = { id = "151", tl = "CORN" },
	 = { id = "152" },
	 = { id = "153" },
	 = { id = "154" },
	 = { id = "155", vas = true },
	 = { id = "156", tl = "tu+ro2" },
	 = { id = "157" },
	 = { id = "158" },
	 = { id = "159", tl = "TELA" },
	 = { id = "160" },
	 = { id = "161" },
	 = { id = "162", tl = "TUN" },
	 = { id = "163", tl = "ARM" },
	 = { id = "164" },
	 = { id = "165" },
	 = { id = "166" },
	 = { id = "167" },
	 = { id = "168" },
	 = { id = "169" },
	 = { id = "170" },
	 = { id = "171" },
	 = { id = "172" },
	 = { id = "173", tl = "LUNA" },
	 = { id = "174" },
	-- *175
	 = { id = "176", tl = "ARB" },
	 = { id = "177" },
	 = { id = "178" },
	 = { id = "179" },
	 = { id = "180" },
	 = { id = "181" },
	 = { id = "182" },
	 = { id = "183" },
	 = { id = "184" },
	 = { id = "185" },
	-- *186, *187, *188
	 = { id = "189" },
	 = { id = "190" },
	 = { id = "191", tl = "GAL" },
	 = { id = "200", vas = true },
	 = { id = "201", vas = true },
	 = { id = "202", vas = true },
	 = { id = "203", vas = true },
	 = { id = "204", vas = true },
	 = { id = "205", vas = true },
	 = { id = "206", vas = true },
	 = { id = "207", vas = true },
	 = { id = "208", vas = true },
	 = { id = "209", tl = "AMPH", vas = true },
	 = { id = "210", vas = true },
	 = { id = "211", vas = true },
	 = { id = "212", vas = true },
	 = { id = "213", vas = true },
	 = { id = "214", vas = true },
	 = { id = "215", vas = true },
	 = { id = "216", vas = true },
	 = { id = "217", vas = true },
	 = { id = "218", vas = true },
	 = { id = "219", vas = true },
	 = { id = "220" },
	 = { id = "221", vas = true },
	 = { id = "222", vas = true },
	 = { id = "225", tl = "ALV" },
	 = { id = "226", vas = true },
	 = { id = "227", vas = true },
	 = { id = "228", vas = true },
	 = { id = "229", vas = true },
	 = { id = "230", tl = "HAS" },
	 = { id = "231", tl = "SAG" },
	 = { id = "232" },
	 = { id = "233", tl = "PUG" },
	 = { id = "234" },
	-- *235
	 = { id = "236", tl = "GUP" },
	-- *237, *238, *239
	 = { id = "240", tl = "BIG" },
	 = { id = "241", tl = "CUR" },
	 = { id = "242", tl = "CAPS" },
	 = { id = "243", tl = "ROTA" },
	-- *244, variant of *243 ?
	 = { id = "245" },
	 = { id = "246" },
	 = { id = "247", tl = "di+pte" },
	 = { id = "248" },
	 = { id = "249" },
	 = { id = "250", vas = true },
	 = { id = "251" },
	 = { id = "252" },
	 = { id = "253" },
	 = { id = "254", tl = "JAC" },
	 = { id = "255" },
	 = { id = "256" },
	 = { id = "257" },
	 = { id = "258" },
	 = { id = "259" },
	 = { id = "305", vas = true },
}

function export.tr(text, lang, sc)
	-- Space between ideograms, syllabograms, and digits, or throw an error if there is apparently a missing space.
	-- TODO: Have a thorough check whether certain spaceless combination are really impossible, and adjust the error throwing if not.
	local space_between = { "", "@", "", "" }
	for i_a, v_a in ipairs(space_between) do
		for i_b, v_b in ipairs(space_between) do
			if i_a ~= i_b or i_a < 3 or i_b < 3 then -- prevents spaces between syllabograms and digits
				text = gsub(text, "("..v_a..spec_char..")("..v_b..")", function(a, b)
					if i_b < 4 then -- if the second char is not a digit, there's a missing space.
						error("There seems to be a missing space.")
					end	
					return a.." "..b
				end)
			end
		end
	end
	-- Put a hyphen between syllabograms.
	for i = 1, 2 do
		text = gsub(text, "(]"..spec_char..")()", "%1-%2")
	end
	-- Numerals.
	text = gsub(text, "+", function(str)
		local ret, count = gsub(str, "^(?)(?)(?)(?)(?)$", function (u5, u4, u3, u2, u1)
			return dig_chars + dig_chars + dig_chars + dig_chars + dig_chars
		end)
		if count ~= 1 then
			error("The number " .. str .. " is weird. Are you sure?")
		end
		return ret
	end)
	-- Syllabograms and ideograms.
	text = gsub(text, "@?", function(x_text)
		x = chars
		if x == nil then error("The symbol " .. x_text .. " is not recognised.") end
		return x.tl or ("*"..x.id..(x.vas and "<sup>VAS</sup>" or ""))
	end)
	-- Symbols.
	text = gsub(text, "(𐄀 ?"..format_char.." ?%] ?"..format_char.." ?)-", "%1")
	text = gsub(text, " ?𐄀 ?", ", ")
	text = gsub(text, " (%}⟧⟩]) *", "%1 ")
	text = gsub(text, " *() ", " %1")
	-- The end.
	return text
end

return export