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

มอดูล:shn-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:shn-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 con_cls = "([ၵၶၷꧠငၸꧡၹꧢၺꩦꩧꩨꩩꧣတထၻꩪၼပၽၾၿꧤမယရလဝႀသႁꩮဢ])"
local med_cls = "([ျြႂ]?)"

local tt1 = {
	-- consonants
	["ၵ"] = "ก", ["ၶ"] = "ข", ["ၷ"] = "ค", ["ꧠ"] = "ฆ", ["င"] = "ง",
	["ၸ"] = "จ", ["ꧡ"] = "ฉ", ["ၹ"] = "ซ", ["ꧢ"] = "ฌ", ["ၺ"] = "ญ",
	["ꩦ"] = "ฏ", ["ꩧ"] = "ฐ", ["ꩨ"] = "ฑ", ["ꩩ"] = "ฒ", ["ꧣ"] = "ณ",
	["တ"] = "ต", ["ထ"] = "ถ", ["ၻ"] = "ท", ["ꩪ"] = "ธ", ["ၼ"] = "น",
	["ပ"] = "ป", ["ၽ"] = "ผ", ["ၾ"] = "ฝ", ["ၿ"] = "พ", ["ꧤ"] = "ภ", ["မ"] = "ม",
	["ယ"] = "ย", ["ရ"] = "ร", ["လ"] = "ล", ["ဝ"] = "ว",
	["ႀ"] = "ษ", ["သ"] = "ส", ["ႁ"] = "ห", ["ꩮ"] = "ฬ", ["ဢ"] = "อ",
	-- medials
	["ျ"] = "ฺย", ["ြ"] = "ฺร", ["ႂ"] = "ฺว",
	-- dependent vowels and diacritics (excluding front type)
	["ၢ"] = "า", ["ႃ"] = "า", ["ိ"] = "ิ", ["ီ"] = "ี",
	["ု"] = "ุ", ["ူ"] = "ู", ["ွ"] = "อ̂", ["်"] = "์", ["ႆ"] = "ย์", -- killer mark gonna remove later
	["ေ"] = "↶เ", ["ဵ"] = "↶เ", ["ႄ"] = "↶แ", ["ႅ"] = "↶แ",
	-- tones
	["ႇ"] = "่", ["ႈ"] = "้", ["း"] = "๊", ["ႉ"] = "๎", ["ႊ"] = "๋",
	-- punctuation marks
	["၊"] = ",", ["။"] = ".",
	-- numerals
	["႐"] = "0", ["႑"] = "1", ["႒"] = "2", ["႓"] = "3", ["႔"] = "4",
	["႕"] = "5", ["႖"] = "6", ["႗"] = "7", ["႘"] = "8", ["႙"] = "9",
	["၀"] = "0", ["၁"] = "1", ["၂"] = "2", ["၃"] = "3", ["၄"] = "4",
	["၅"] = "5", ["၆"] = "6", ["၇"] = "7", ["၈"] = "8", ["၉"] = "9",
	-- zero-width space (display it if it hides in a word)
	[u(0x200B)] = "‼", [u(0x200C)] = "‼", [u(0x200D)] = "‼",
}

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, con_cls .. med_cls .. "([ၵငတၼပမၺ]်)", "%1%2ั%3")
	text = gsub(text, con_cls .. med_cls .. "(ႆ)", "%1%2↶ไ")
	text = gsub(text, con_cls .. med_cls .. "(ေႃ)", "%1%2อ̂")
	text = gsub(text, con_cls .. med_cls .. "(ို)", "%1%2ึ")
	text = gsub(text, con_cls .. med_cls .. "(ိူ)", "%1%2↶เิ")
	text = gsub(text, con_cls .. "([ျြ]?)(ႂ်)", "%1%2↶ใ") -- unable to have medial -w

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

	text = gsub(text, "([ก-ฮ]์)([่้๊๋๎])", "%2%1")
	text = gsub(text, "(อ̂)([่้๊๋๎])", "%2%1")
	text = gsub(text, "(า)([่้๊๋๎])", "%2%1")

	text = gsub(text, "(.)↶([เแใไ])", "%2%1")
	text = gsub(text, "์", "") -- remove killer mark

	return text
 
end
 
return export