ข้ามไปเนื้อหา

มอดูล:Sund-translit

จาก วิกิพจนานุกรม พจนานุกรมเสรี

This module will transliterate text in the อักษรซุนดา. 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:Sund-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.

local export = {}
local gsub = mw.ustring.gsub
local u = mw.ustring.char

local tt = {
	-- initials
	["ᮊ"] = "ก", ["ᮌ"] = "ค", ["ᮍ"] = "ง", ["ᮎ"] = "จ", ["ᮏ"] = "ช", ["ᮑ"] = "ญ",
	["ᮒ"] = "ต", ["ᮓ"] = "ท", ["ᮔ"] = "น", ["ᮕ"] = "ป", ["ᮘ"] = "พ", ["ᮙ"] = "ม",
	["ᮚ"] = "ย", ["ᮛ"] = "ร", ["ᮜ"] = "ล", ["ᮝ"] = "ว", ["ᮞ"] = "ส", ["ᮠ"] = "ห",
	["ᮖ"] = "ฟ", ["ᮋ"] = "ก̱", ["ᮗ"] = "ว̱", ["ᮟ"] = "กฺษ", ["ᮐ"] = "ซ",
	["ᮮ"] = "ฅ", ["ᮯ"] = "ศ", ["ᮺ"] = "-", ["ᮽ"] = "ภ",
	-- medials
	["ᮡ"] = "ฺย", ["ᮢ"] = "ฺร", ["ᮣ"] = "ฺล", ["ᮬ"] = "ฺม", ["ᮭ"] = "ฺว",
	-- independent vowels
	["ᮃ"] = "อ", ["ᮄ"] = "อิ", ["ᮅ"] = "อุ",
	["ᮆ"] = "อ↶แ", ["ᮇ"] = "ออ̂", ["ᮈ"] = "อ↶เอ̂", ["ᮉ"] = "อึ",
	["ᮻ"] = "ฤ", ["ᮼ"] = "ฦ",
	-- dependent vowels and diacritics
	["ᮤ"] = "ิ", ["ᮥ"] = "ุ",
	["ᮦ"] = "↶แ", ["ᮧ"] = "อ̂", ["ᮨ"] = "↶เอ̂", ["ᮩ"] = "ึ",
	["᮪"] = "ฺ", ["᮫"] = "ฺ",
	["ᮀ"] = "ํ", ["ᮁ"] = "รฺ", ["ᮂ"] = "ะ",
	-- finals
	["ᮾ"] = "กฺ", ["ᮿ"] = "มฺ",
	-- numerals
	["᮰"] = "0", ["᮱"] = "1", ["᮲"] = "2", ["᮳"] = "3", ["᮴"] = "4",
	["᮵"] = "5", ["᮶"] = "6", ["᮷"] = "7", ["᮸"] = "8", ["᮹"] = "9",
	-- zero-width space (display it if it hides in a word)
	[u(0x200B)] = "‼",
}

function export.tr(text, lang, sc, debug_mode)

	if type(text) == "table" then -- called directly from a template
		text = text.args[1]
	end

	text = gsub(text, ".", tt)

	text = gsub(text, "([ก-ฮ]̱?)↶([เแ])", "%2%1")

	-- ย้ายสัญลักษณ์ขึ้นบน เมื่อมีสระล่าง (ยกเว้นตัวที่ไม่มี)
	text = gsub(text, u(0x0331).."([ุ-ฺ])", u(0x0304).."%1") -- macron below > macron above

	return text

end

return export