มอดูล:mnw-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:mnw-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 letter_with_mark = "(.["..u(0x0300).."-"..u(0x036F).."]?)"

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

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

local tt2 = {
	-- vowels (2 chars)
	["ဣဳ"] = "อี", ["ဥု"] = "อู",
	["ဴ"] = "เ%1า", ["ေ"] = "เ%1",
	["ေါ"] = "โ%1", ["ော"] = "โ%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)

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

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

	return text
 
end
 
return export