Module:bo-translit

ពីWiktionary

Documentation for this module may be created at Module:bo-translit/doc

local export = {}

local conv = {
	['ཀ'] = "k", ['ཁ'] = "kh", ['ག'] = "g", ['ང'] = "ng", 
	['ཅ'] = "c", ['ཆ'] = "ch", ['ཇ'] = "j", ['ཉ'] = "ny", 
	['ཏ'] = "t", ['ཐ'] = "th", ['ད'] = "d", ['ན'] = "n", 
	['པ'] = "p", ['ཕ'] = "ph", ['བ'] = "b", ['མ'] = "m", 
	['ཙ'] = "ts", ['ཚ'] = "tsh", ['ཛ'] = "dz", ['ཝ'] = "w", 
	['ཞ'] = "zh", ['ཟ'] = "z", ['འ'] = "'", ['ཡ'] = "y", 
	['ར'] = "r", ['ལ'] = "l", ['ཤ'] = "sh", ['ས'] = "s", 
	['ཧ'] = "h", ['ཨ'] = "a", 
	['ཊ'] = "ṭ", ['ཋ'] = "ṭh", ['ཌ'] = "ḍ", ['ཎ'] = "ṇ", ['ཥ'] = "ṣ", 
	
	['\224\189\178'] = "i", 
	['\224\189\180'] = "u", 
	['\224\189\186'] = "e", 
	['\224\189\188'] = "o", 
	['\224\189\177'] = "ā", 
	['\224\189\177\224\189\178'] = "ī", 
	['\224\189\177\224\189\180'] = "ū", 
	['\224\189\187'] = "ai", 
	['\224\189\189'] = "au", 
	['\224\190\178\224\190\128'] = "ṛ", 
	['\224\189\183'] = "ṝ", 
	['\224\190\179\224\190\128'] = "ḷ", 
	['\224\189\185'] = "ḹ", 
	['\224\189\190'] = 'ṃ', 
	['\224\190\131'] = "ṃ", 
	['\224\189\191'] = "aḥ", 
	
	['ྐ'] = "k", ['ྑ'] = "kh", ['ྒ'] = "g", ['ྔ'] = "ng", 
	['ྕ'] = "c", ['ྖ'] = "ch", ['ྗ'] = "j", ['ྙ'] = "ny", 
	['ྟ'] = "t", ['ྠ'] = "th", ['ྡ'] = "d", ['ྣ'] = "n", 
	['ྤ'] = "p", ['ྥ'] = "ph", ['ྦ'] = "b", ['ྨ'] = "m", 
	['ྩ'] = "ts", ['ྪ'] = "tsh", ['ྫ'] = "dz", ['ྭ'] = "w", 
	['ྮ'] = "zh", ['ྯ'] = "z", ['ྰ'] = "'", ['ྱ'] = "y", 
	['ྲ'] = "r", ['ླ'] = "l", ['ྴ'] = "sh", ['ྶ'] = "s", 
	['ྷ'] = "h", ['ྸ'] = "a", 
	['ྚ'] = "ṭ", ['ྛ'] = "ṭh", ['ྜ'] = "ḍ", ['ྞ'] = "ṇ", ['ྵ'] = "ṣ"
}

local symbol = {
	['༠'] = '0', ['༡'] = '1', ['༢'] = '2', ['༣'] = '3', ['༤'] = '4',
	['༥'] = '5', ['༦'] = '6', ['༧'] = '7', ['༨'] = '8', ['༩'] = '9',
	['༪'] = '0.5', ['༫'] = '1.5', ['༬'] = '2.5', ['༭'] = '3.5', ['༮'] = '4.5', 
	['༯'] = '5.5', ['༰'] = '6.5', ['༱'] = '7.5', ['༲'] = '8.5', ['༳'] = '9.5',
}

function export.tr(text, lang, sc, debug_mode)
	for Tibetan_word in mw.ustring.gmatch(text, '[་-༑ཀ-ྼ]+') do
		local original_word = Tibetan_word
		local output = {}
		Tibetan_word = mw.ustring.gsub(Tibetan_word, '[\224\188\139\224\188\141]+$', '')
		
		for syllable in mw.text.gsplit(Tibetan_word, '\224\188\139', true) do
			local tr = {}

			local syl = mw.ustring.gsub(syllable, '\224\189\168([\224\189\177\224\189\178\224\189\186\224\189\188\224\189\178\224\189\180\224\190\178\224\189\183\224\190\179\224\189\185\224\189\190\224\189\191])', '%1')
			syl = mw.ustring.gsub(syl, '([\224\190\144\224\190\145\224\190\146\224\190\148\224\190\149\224\190\150\224\190\151\224\190\153\224\190\159\224\190\160\224\190\161\224\190\163\224\190\164\224\190\165\224\190\166\224\190\168\224\190\169\224\190\170\224\190\171\224\190\174\224\190\175\224\190\173\224\190\176\224\190\177\224\190\178\224\190\179\224\190\180\224\190\182\224\190\183\224\190\184]+)([^\224\189\177\224\189\178\224\189\186\224\189\188\224\189\178\224\189\180\224\190\178\224\189\183\224\190\179\224\189\185\224\189\190\224\189\191\224\190\144\224\190\145\224\190\146\224\190\148\224\190\149\224\190\150\224\190\151\224\190\153\224\190\159\224\190\160\224\190\161\224\190\163\224\190\164\224\190\165\224\190\166\224\190\168\224\190\169\224\190\170\224\190\171\224\190\174\224\190\175\224\190\173\224\190\176\224\190\177\224\190\178\224\190\179\224\190\180\224\190\182\224\190\183\224\190\184]*)$', '%1a%2')
			syl = mw.ustring.gsub(syl, '^([^\224\189\177\224\189\178\224\189\186\224\189\188\224\189\178\224\189\180\224\190\178\224\189\183\224\190\179\224\189\185\224\189\190\224\189\191]+)(\224\189\160[\224\189\177\224\189\178\224\189\186\224\189\188\224\189\178\224\189\180\224\190\178\224\189\183\224\190\179\224\189\185\224\189\190\224\189\191])$', '%1a%2')
			letter = mw.text.split(syl, "", true)
			for i = 1, #letter do
				tr[i] = conv[letter[i]] or letter[i]
			end

			if mw.ustring.find(syllable,'[\224\190\144\224\190\145\224\190\146\224\190\148\224\190\149\224\190\150\224\190\151\224\190\153\224\190\159\224\190\160\224\190\161\224\190\163\224\190\164\224\190\165\224\190\166\224\190\168\224\190\169\224\190\170\224\190\171\224\190\174\224\190\175\224\190\173\224\190\176\224\190\177\224\190\178\224\190\179\224\190\180\224\190\182\224\190\183\224\190\184\224\189\178\224\189\186\224\189\188\224\189\180\224\189\168\224\189\177\224\189\177\224\189\177\224\189\178\224\189\187\224\189\189\224\189\180\224\190\178\224\190\128\224\189\183\224\190\179\224\190\128\224\189\185\224\189\190\224\190\131\224\189\191]') then
				if #letter < 4 and letter[2] == 'འ' and mw.ustring.match(letter[3], '[\224\189\178\224\189\186\224\189\188\224\189\180]') then
					table.insert(tr, 2, "a'")
				end
			elseif #letter < 5 then
				if #letter > 3 then
					if letter[2] ~= 'འ' and letter[3] ~= 'འ' then
						table.insert(tr, 3, "a")
					end
				elseif #letter > 2 then
					if letter[3] == 'འ' then
						if letter[1] == 'འ' then
							tr = { "'", tr[2], "a", "'" }
						else
							tr = { tr[1], tr[2], "a", "'" }
						end
					elseif not mw.ustring.match(letter[1], '[གདབའམ]') or (mw.ustring.match(letter[1], '[གདབའམ]') and mw.ustring.match(letter[2], '[གངཐབམའརལ]') and mw.ustring.match(letter[3], '[ནས]')) then
						table.insert(tr, 2, "a")
					else
						table.insert(tr, 3, "a")
					end
				elseif mw.ustring.match(letter[1], '[གདབའམ]') and not mw.ustring.find(letter[2] or '', '[གངདཐབམའརལསན]') then
					table.insert(tr, "a")
				else
					table.insert(tr, 2, "a")
				end
			end

			tr = table.concat(tr)
			if mw.ustring.find(syllable, 'གཡ') then
				tr = mw.ustring.gsub(tr, 'gy', 'g.y')
			end
			table.insert(output, tr)
		end
		Tibetan_word = table.concat(output, " ")
		text = mw.ustring.gsub(text, original_word, Tibetan_word)
	end
	
	text = mw.ustring.gsub(text, '.', symbol)
	
	if mw.ustring.match(text, '[ཀ-ྼ]') and not debug_mode then
		return nil
	else
		return text
	end
end

return export