มอดูล:my-translit

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

This module will transliterate ภาษาพม่า text. 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:my-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 = {
	-- consonants
	["က"] = "ก", ["ခ"] = "ข", ["ဂ"] = "ค", ["ဃ"] = "ฆ", ["င"] = "ง",
	["စ"] = "จ", ["ဆ"] = "ฉ", ["ဇ"] = "ช", ["ဈ"] = "ฌ", ["ဉ"] = "ญ", ["ည"] = "ญ",
	["ဋ"] = "ฏ", ["ဌ"] = "ฐ", ["ဍ"] = "ฑ", ["ဎ"] = "ฒ", ["ဏ"] = "ณ",
	["တ"] = "ต", ["ထ"] = "ถ", ["ဒ"] = "ท", ["ဓ"] = "ธ", ["န"] = "น",
	["ပ"] = "ป", ["ဖ"] = "ผ", ["ဗ"] = "พ", ["ဘ"] = "ภ", ["မ"] = "ม",
	["ယ"] = "ย", ["ရ"] = "ร", ["လ"] = "ล", ["ဝ"] = "ว",
	["သ"] = "ส", ["ဟ"] = "ห", ["ဠ"] = "ฬ", ["အ"] = "อ",
	["ဿ"] = "สฺส",
	-- independent vowels
	["ဣ"] = "อิ", ["ဤ"] = "อี", ["ဥ"] = "อุ", ["ဦ"] = "อู",
	["ဧ"] = "เอ", ["ဩ"] = "เอา:", ["ဪ"] = "เอา̥",
	-- dependent vowels and diacritics (excluding front type)
	["ါ"] = "า", ["ာ"] = "า", ["ိ"] = "ิ", ["ီ"] = "ี", ["ု"] = "ุ", ["ူ"] = "ู",
	["ံ"] = "ํ", ["့"] = "̥", ["း"] = ":", ["္"] = "ฺ", ["်"] = "์",
	["ျ"] = "ฺย", ["ြ"] = "ฺร", ["ွ"] = "ฺว",
	-- marks
	["၊"] = ",", ["။"] = ".",
	["၌"] = "หฺไนก์", ["၍"] = "รุย์", ["၎"] = "ฯ", ["၏"] = "เออ์‌",
	-- 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, "(့)([ါ-ှ])", "%2%1") -- swap tone-3 mark and vowel
	text = gsub(text, ".", tt)

	text = gsub(text, "(.)ှ", "หฺ%1")
	text = gsub(text, "(.)ေ", "เ%1")
	text = gsub(text, "(.)ဲ", "แ%1")

	text = gsub(text, "(.)ิุ", "โ%1") -- อิุ -> โอ
	text = gsub(text, "โ(.)([ก-รวสฬอ]์)", "ไ%1%2") -- โอx์ -> ไอx์ ยกเว้น ลหฮ

	text = gsub(text, "([เแไโ])อฺ", "อฺ%1")

	return text
 
end
 
return export