Module:peo-translit

From Linguifex
Jump to navigation Jump to search

Documentation for this module may be created at Module:peo-translit/doc

local export = {}

local alphabetic_tt = {
	-- this should only contain alphabetic characters
	["๐Ž "] = "a",
	["๐Žก"] = "i",
	["๐Žข"] = "u",
	["๐Žฃ"] = "k",
	["๐Žค"] = "ku",
	["๐Žฅ"] = "g",
	["๐Žฆ"] = "gu",
	["๐Žง"] = "x",
	["๐Žจ"] = "c",
	["๐Žฉ"] = "j",
	["๐Žช"] = "ji",
	["๐Žซ"] = "t",
	["๐Žฌ"] = "tu",
	["๐Žญ"] = "d",
	["๐Žฎ"] = "di",
	["๐Žฏ"] = "du",
	["๐Žฐ"] = "ฮธ",
	["๐Žฑ"] = "p",
	["๐Žฒ"] = "b",
	["๐Žณ"] = "f",
	["๐Žด"] = "n",
	["๐Žต"] = "nu",
	["๐Žถ"] = "m",
	["๐Žท"] = "mi",
	["๐Žธ"] = "mu",
	["๐Žน"] = "y",
	["๐Žบ"] = "v",
	["๐Žป"] = "vi",
	["๐Žผ"] = "r",
	["๐Žฝ"] = "ru",
	["๐Žพ"] = "l",
	["๐Žฟ"] = "s",
	["๐€"] = "z",
	["๐"] = "ลก",
	["๐‚"] = "รง",
	["๐ƒ"] = "h",
	["๐ˆ"] = "AM", -- Auramazdฤ
	["๐‰"] = "AM", -- Auramazdฤ
	["๐Š"] = "AMha", -- Auramazdฤha
	["๐‹"] = "Xล ", -- xลกฤyathiya 
	["๐Œ"] = "DH", -- dahyฤuลก
	["๐"] = "DH", -- dahyฤuลก
	["๐Ž"] = "BG", -- baga
	["๐"] = "BU", -- bลซmiลก
}

local nonalphabetic_tt = {
	["๐"] = " : ", --word divider
}

local numbers = {
	["๐‘"] = 1,
	["๐’"] = 2,
	["๐“"] = 10,
	["๐”"] = 20,
	["๐•"] = 100,
}

function export.convert_numbers(numeric_str)
	local total = 0
	for c in mw.ustring.gmatch(numeric_str, ".") do
		total = total + numbers[c]
	end
	return total
end

function export.tr(text, lang, sc)
	-- If the script is not Xpeo, do not transliterate
	if sc ~= "Xpeo" then
		return
	end
	
	local t = {}
	local preceding_num = false
	local need_hyphen = false
	-- Transliterate characters
	text = mw.ustring.gsub(text,
		".",
		function(c)
			if alphabetic_tt[c] then
				if need_hyphen then
					t[#t + 1] = "-"
				end
				t[#t + 1] = alphabetic_tt[c]
				need_hyphen = true
			else
				need_hyphen = false
				if numbers[c] then
					if preceding_num then
						t[#t] = t[#t] + numbers[c]
					else
						t[#t + 1] = numbers[c]
					end
					preceding_num = true
				else
					preceding_num = false
					t[#t + 1] = nonalphabetic_tt[c] or c
				end
			end
		end)

	return table.concat(t)
end

return export