มอดูล:ug-translit-Thai

จาก วิกิพจนานุกรม พจนานุกรมเสรี
ไปยังการนำทาง ไปยังการค้นหา
local export = {}
local gsub = mw.ustring.gsub
local u = mw.ustring.char

local data = {}

data["ug-Arab"] = {
	-- consonants
	["م"] = "ม",  ["ن"] = "น",  ["د"] = "ด",  ["ت"] = "ต",
	["ب"] = "บ",  ["پ"] = "ป",  ["ف"] = "ฟ",  ["ق"] = "ก̤",
	["ك"] = "ก",  ["ڭ"] = "ง", ["گ"] = "ก̱",  ["غ"] = "ฆ",
	["ھ"] = "ฮ",  ["خ"] = "ค",  ["چ"] = "ช",
	["ج"] = "จ", ["ژ"] = "ซ̤", ["ز"] = "ซ̱",  ["س"] = "ซ",
	["ش"] = "ฌ", ["ر"] = "ร",  ["ل"] = "ล",  ["ئ"] = "อ",
	["ي"] = "ย",  ["ۋ"] = "ว",
	-- vowels
	["ا"] = "า", ["ە"] = "↶แ", ["ې"] = "↶เ", ["ى"] = "ี",
	["و"] = "↶โ", ["ۆ"] = "↶เิ", ["ۇ"] = "ู", ["ۈ"] = "ื",
	-- punctuation
	["؟"]="?",
	["،"]=",",
	["؛"]=";",
	["ـ"]="-",
	-- zero-width space (display it if it hides in a word)
	[u(0x200B)] = "‼", [u(0x200C)] = "‼", [u(0x200D)] = "‼",
}

data["Arab"] = data["ug-Arab"]

data["Cyrl"] = {
	["А"] = "า", ["Б"] = "บ", ["В"] = "ว", ["Г"] = "ก̱", ["Ғ"] = "ฆ", ["Д"] = "ด", ["Е"] = "↶เ", ["Ә"] = "↶แ", ["Ж"] = "ซ̤", ["Җ"] = "จ",
	["З"] = "ซ̱", ["И"] = "ี", ["Й"] = "ย", ["К"] = "ก", ["Қ"] = "ก̤", ["Л"] = "ล", ["М"] = "ม", ["Н"] = "น", ["Ң"] = "ง", ["О"] = "↶โ",
	["Ө"] = "↶เิ", ["П"] = "ป", ["Р"] = "ร", ["С"] = "ซ", ["Т"] = "ต", ["У"] = "ู", ["Ү"] = "ื", ["Ф"] = "ฟ", ["Х"] = "ค", ["Һ"] = "ฮ",
	["Ч"] = "ช", ["Ш"] = "ฌ", ["Ю"] = "ยู", ["Я"] = "ยา",
	["Э"] = "↶เ",
	["а"] = "า", ["б"] = "บ", ["в"] = "ว", ["г"] = "ก̱", ["ғ"] = "ฆ", ["д"] = "ด", ["е"] = "↶เ", ["ә"] = "↶แ", ["ж"] = "ซ̤", ["җ"] = "จ",
	["з"] = "ซ̱", ["и"] = "ี", ["й"] = "ย", ["к"] = "ก", ["қ"] = "ก̤", ["л"] = "ล", ["м"] = "ม", ["н"] = "น", ["ң"] = "ง", ["о"] = "↶โ",
	["ө"] = "↶เิ", ["п"] = "ป", ["р"] = "ร", ["с"] = "ซ", ["т"] = "ต", ["у"] = "ู", ["ү"] = "ื", ["ф"] = "ฟ", ["х"] = "ค", ["һ"] = "ฮ",
	["ч"] = "ช", ["ш"] = "ฌ", ["ю"] = "ยู", ["я"] = "ยา",
	["э"] = "↶เ",
}


function export.tr(text, lang, sc)
	if not sc then
		sc = require("Module:scripts").findBestScript(text, require("Module:languages").getByCode(lang)):getCode()
	end
	
	text = gsub(text, "^([аеәиоөуүАЕӘИОӨУҮ])", "อ%1")
	text = gsub(text, "([%s%p])([аеәиоөуүАЕӘИОӨУҮ])", "%1อ%2")
	text = gsub(text, "([аеәиоөуүАЕӘИОӨУҮ])([аеәиоөуүАЕӘИОӨУҮ])", "%1อ%2")
	
	text = gsub(text, ".", data[sc])

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

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

	return text
end

return export