มอดูล:mnw-translit

จาก วิกิพจนานุกรม พจนานุกรมเสรี
ไปยังการนำทาง ไปยังการค้นหา

มอดูลนี้ใช้ถอดอักษรข้อความภาษามอญ.

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 มอดูล:mnw-translit/testcases.

ฟังก์ชัน[แก้ไข]

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

local export = {}
local gsub = mw.ustring.gsub
local u = mw.ustring.char
local letter_with_mark = "(.["..u(0x0300).."-"..u(0x036F).."]?)"

local pre = {
	["ျ"] = "္ယ", ["ြ"] = "္ရ", ["ွ"] = "္ဝ", ["ှ"] = "္ဟ",
	["ၞ"] = "္န", ["ၟ"] = "္မ", ["ၠ"] = "္လ",
}

local tt1 = {
	-- consonants
	["က"] = "ก", ["ခ"] = "ข", ["ဂ"] = "ค", ["ဃ"] = "ฆ", ["င"] = "ง", ["ၚ"] = "ง",
	["စ"] = "จ", ["ဆ"] = "ฉ", ["ဇ"] = "ช", ["ၛ"] = "ฌ", ["ဉ"] = "ญ", ["ည"] = "ญ",
	["ဋ"] = "ฏ", ["ဌ"] = "ฐ", ["ဍ"] = "ฑ", ["ဎ"] = "ฒ", ["ဏ"] = "ณ",
	["တ"] = "ต", ["ထ"] = "ถ", ["ဒ"] = "ท", ["ဓ"] = "ธ", ["န"] = "น",
	["ပ"] = "ป", ["ဖ"] = "ผ", ["ဗ"] = "พ", ["ဘ"] = "ภ", ["မ"] = "ม",
	["ယ"] = "ย", ["ရ"] = "ร", ["လ"] = "ล", ["ဝ"] = "ว", ["သ"] = "ส", ["ဿ"] = "สฺส",
	["ဟ"] = "ห", ["ဠ"] = "ฬ", ["ၜ"] = "บ", ["အ"] = "อ", ["ၝ"] = "มฺบ",
	-- independent vowels (1)
	["ဣ"] = "อิ", ["ဥ"] = "อุ",
	["ဨ"] = "เอ", ["ဩ"] = "เอา",
	-- dependent vowels and diacritics (excluding front type)
	["ါ"] = "า", ["ာ"] = "า", ["ိ"] = "ิ", ["ီ"] = "ิํ", ["ဳ"] = "ี", ["ု"] = "ุ", ["ူ"] = "ู", ["ဲ"] = "ัว", 
	["ံ"] = "ํ", ["့"] = "̥", ["း"] = ":", ["္"] = "ฺ", ["်"] = "์",
	-- numerals
	["၀"] = "๐", ["၁"] = "๑", ["၂"] = "๒", ["၃"] = "๓", ["၄"] = "๔",
	["၅"] = "๕", ["၆"] = "๖", ["၇"] = "๗", ["၈"] = "๘", ["၉"] = "๙",
	-- zero-width space (display it if it hides in a word)
	[u(0x200B)] = "‼",
}

local tt2 = {
	-- independent vowels (2)
	["ဣဳ"] = "อี", ["ဥု"] = "อู",
}

local adjust1 = {
	-- dependent vowels (front type)
	["ဴ"] = "เ%1า", ["ဵ"] = "เ%1", ["ေ"] = "เ%1",
}

local adjust2 = {
	-- dependent vowels (front type)
	["ေါ"] = "เ%1า", ["ော"] = "เ%1า", ["ဵု"] = "เ%1อ̂",
	["ဲါ"] = "ไ%1", ["ဲာ"] = "ไ%1",
}

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, ".", pre)

	text = gsub(text, "..", tt2)
	for k, v in pairs(adjust2) do
		text = gsub(text, letter_with_mark..k, v)
	end

	text = gsub(text, ".", tt1)
	for k, v in pairs(adjust1) do
		text = gsub(text, letter_with_mark..k, v)
	end

	return text
 
end
 
return export