မာတိကာသို့ ခုန်သွားရန်

မဝ်ဂျူ:blk-translit

နူ ဝိက်ရှေန်နရဳ

Documentation for this module may be created at မဝ်ဂျူ:blk-translit/doc

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

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

local tt1 = {
	["က"] = "kᵃ", ["ခ"] = "khᵃ", ["ဂ"] = "gᵃ", ["ဃ"] = "ghᵃ", ["င"] = "ṅᵃ", 
	["စ"] = "cᵃ", ["ဆ"] = "chᵃ", ["ဇ"] = "jᵃ", ["ဈ"] = "jhᵃ", ["ဉ"] = "ñᵃ", ["ည"] = "ññᵃ",  -- ññ -> ñ later
	["ဋ"] = "ṭᵃ", ["ဌ"] = "ṭhᵃ", ["ဍ"] = "ḍᵃ", ["ဎ"] = "ḍhᵃ", ["ဏ"] = "ṇᵃ", ["ၮ"] = "ṇᵃ",
	["တ"] = "tᵃ", ["ထ"] = "thᵃ", ["ဒ"] = "dᵃ", ["ဓ"] = "dhᵃ", ["န"] = "nᵃ",
	["ပ"] = "pᵃ", ["ဖ"] = "phᵃ", ["ဗ"] = "bᵃ", ["ဘ"] = "bhᵃ", ["မ"] = "mᵃ",
	["ယ"] = "yᵃ", ["ရ"] = "rᵃ", ["လ"] = "lᵃ", ["ဝ"] = "wᵃ", ["သ"] = "śᵃ", ["ဿ"] = "śśᵃ",
	["ဟ"] = "hᵃ", ["ဠ"] = "ḷᵃ",  ["အ"] = "ʼᵃ",  
	-- independent vowels (1 char)
	["ဣ"] = "ʼi", ["ဥ"] = "ʼu", ["ဩ"] = "ʼo",
	-- dependent vowels and diacritics (1 char)
	["ါ"] = "ā", ["ာ"] = "ā", ["ိ"] = "i", ["ီ"] = "ī", ["ု"] = "u", ["ူ"] = "ū", ["ဲ"] = "ʸ",
	["ေ့"] = "e", ["ေ"] = "ē", ["ံ"] = "ṁ", ["း"] = "̌", ["္"] = "¡", ["်"] = "¤",
	-- punctuation marks
	["၊"] = ",", ["။"] = ".", 
	-- numerals
	["၀"] = "0", ["၁"] = "1", ["၂"] = "2", ["၃"] = "3", ["၄"] = "4",
	['𑛐'] = '0', ['𑛑'] = '1', ['𑛒'] = '2', ['𑛓'] = '3', ['𑛔'] = '4',
	["၅"] = "5", ["၆"] = "6", ["၇"] = "7", ["၈"] = "8", ["၉"] = "9",
	['𑛕'] = '5', ['𑛖'] = '6', ['𑛗'] = '7', ['𑛘'] = '8', ['𑛙'] = '9',
	-- zero-width space (display it if it hides in a word)
	[u(0x200B)] = "‼", [u(0x200C)] = "‼", [u(0x200D)] = "‼",
}

-- ⒶⒽⓄⓂ markup for anusvara.
local ahom = {
	["ံⒶ"] = "အ်", ["ံⒽ"] = "ĥ",
	["ံⓄ"] = "ံ", -- default action, at least for now.
	["ံⓂ"] = "ံ", -- default action
}
local tt2 = {
	["ံ[ⒶⒽⓄⓂ]"] = ahom, -- CAUTION: ahom is a table.
	-- vowels (2 chars)
	["ဲ့"] = "ea", ["ꩻ"] = "̀", ["ႏ"] = "́",
	["ုဲင့်"] = "ai", ["ုဲၚ်"] = "āi", ["ော့"] = "ao",
	["ော်"] = "āo", ["ို့"] = "o", ["ို"] = "ō",
	["ိုဝ်ႏ"] = "ṓ",
}

function export.tr(text, lang, sc, debug_mode)

	if type(text) == "table" then -- called directly from a template
		text = text.args[1]
	end

--Punctuation
	text = gsub(text, "( +)", u(0xa0, 0xa0).."%1") -- 2 NBSP before spaces to widen them. 
    text = gsub(text, "<wbr/?>", " ")    -- Insert spaces between words.
	text = gsub(text, "([ှ])(ေ?ါ?ာ?)([်])(ေ?)", 
				function(H,b,A,a) return b..a..'h' end)
	text = gsub(text, ".", pre)
	text = gsub(text, "ဲါ", "ါဲ") -- fixed ay+aa to aa+ay; it often occurs

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

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

	text = gsub(text, "([aeiuoāīū])ʸ", "%1y")
	text = gsub(text, "ᵃʸ", "oa")

	text = gsub(text, "ᵃ([¡¤]+)", "")
	text = gsub(text, "([aeiuoāīū])¤", "%1k")
	text = gsub(text, "ᵃ([aeiuoāīū])", "%1")
	text = gsub(text, "ᵃ", "a")

	text = gsub(text, "iṁu", "iuṁ")
	if lang == "blk" then --Pa'O 
		text = gsub(text, "ññ", "ñ")
	end

	return text
 
end
 
return export