Module:blk-translit

From Wiktionary, the free dictionary
Jump to navigation Jump to search

This module will transliterate Pa'o Karen language 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:blk-translit/testcases.

Functions[edit]

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
	['က'] = 'k', ['ခ'] = 'h̄h', ['ဂ'] = 'kh', ['ဃ'] = 'ḳh', ['င'] = 'ng',
	['စ'] = 'c', ['ဆ'] = 'c̄h', ['ဇ'] = 'ch', ['ဈ'] = 'c̣h', ['ဉ'] = 'ỵ', ['ည'] = 'ỵ',
	['ဋ'] = 't̩', ['ဌ'] = 'ṭ̄', ['ဍ'] = 'ṯh', ['ဎ'] = 'tʹh', ['ဏ'] = 'ṇ',
	['တ'] = 't', ['ထ'] = 't̄h', ['ဒ'] = 'th', ['ဓ'] = 'ṭh', ['န'] = 'n',
	['ပ'] = 'p', ['ဖ'] = 'p̄h', ['ဗ'] = 'ph', ['ဘ'] = 'p̣h', ['မ'] = 'm',
	['ယ'] = 'y', ['ရ'] = 'r', ['လ'] = 'l', ['ဝ'] = 'w', ['သ'] = 's̄',
	['ဟ'] = 'h̄', ['ဠ'] = 'ḷ', ['အ'] = 'x',
	-- independent vowels (1)
	['ဣ'] = 'xi', ['ဤ'] = 'xī', ['ဥ'] = 'xu', ['ဦ'] = 'xū', ['ဩ'] = 'xeā',
	-- dependent vowels and diacritics (excluding front type)
	['ါ'] = 'ā', ['ာ'] = 'ā', ['ိ'] = 'i', ['ီ'] = 'ī', ['ု'] = 'u', ['ူ'] = 'ū',
	['ံ'] = 'ํ', ['့'] = '̥', ['း'] = ':', ['ႏ'] = '⁏', ['ꩻ'] = '⹁', ['္'] = 'ฺ', ['်'] = '์',
	-- numerals
	['၀'] = '0', ['၁'] = '1', ['၂'] = '2', ['၃'] = '3', ['၄'] = '4',
	['၅'] = '5', ['၆'] = '6', ['၇'] = '7', ['၈'] = '8', ['၉'] = '9',
	-- zero-width space (display it if it hides in a word)
	[u(0x200B)] = '‼',
}

local adjust1 = {
	-- dependent vowels (front type)
	['ေ'] = 'e%1', ['ဲ'] = 'æ%1', 
}



function export.tr(text, lang, sc)

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

	text = gsub(text, '.', pre)

	text = gsub(text, '.', tt1)
	for k, v in pairs(adjust1) do
		text = gsub(text, letter_with_mark..k, v)
	end

	return text
 
end
 
return export