Module:Cakm-translit

This module will transliterate text in the Chakma script. It is used to transliterate Chakma and Pali. 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:Cakm-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 u = require("Module:string/char")

-- Stage 1: IAST-style
local consonants = {
--consonants
-- 'ⓨ' is a convenience for language specific modifications. 
	['𑄃']='',
	['𑄇']='k', ['𑄈']='kh', ['𑄉']='g', ['𑄊']='gh', ['𑄋']='ṅ',
	['𑄌']='c', ['𑄍']='ch', ['𑄎']='j', ['𑄏']='jh', ['𑄐']='ñ', 
	['𑄑']='ṭ', ['𑄒']='ṭh', ['𑄓']='ḍ', ['𑄔']='ḍh', ['𑄕']='ṇ', 
	['𑄖']='t', ['𑄗']='th', ['𑄘']='d', ['𑄙']='dh', ['𑄚']='n', 
	['𑄛']='p', ['𑄜']='ph', ['𑄝']='b', ['𑄞']='bh', ['𑄟']='m',
	['𑄠']='y', ['𑄡']='ⓨ', ['𑄢']='r', ['𑄣']='l', ['𑄤']='v', ['𑅇']='v', 
--	['𑀰']='ś', ['𑀱']='ṣ',
	['𑄥']='s', ['𑄦']='h', ['𑅄']='ḷ',
}

local diacritics = {
--matras
	['𑅅']='ā', ['𑄨']='i', ['𑄩']='ī', ['𑄪']='u', ['𑄫']='ū',
--	['𑀾']='ṛ', ['𑀿']='ṝ', ['𑁀']='l̥', ['𑁁']='l̥̄',
	['𑄬']='e', ['𑄭']='ai', ['𑄮']='o', ['𑄯']='au',  ['𑄴']='',  ['𑄳']='',
    -- Oddities
    ['𑄧']='ă', [u(0x11130)]='oi', [u(0x11146)]='ei',
}

local tt = {

--vowels
	['𑄃']='a', ['𑄄']='i', ['𑄅']='u', ['𑄆']='e', 
	-- chandrabindu    
	['𑄀']='m̐', --until a better method is found
	-- anusvara    
	['𑄁']='ṃ', --until a better method is found
	-- visarga    
	['𑄂']='ḥ',
	--numerals
	['𑄶']='0', ['𑄷']='1', ['𑄸']='2', ['𑄹']='3', ['𑄺']='4', ['𑄻']='5', ['𑄼']='6', ['𑄽']='7', ['𑄾']='8', ['𑄿']='9',
	--punctuation        
	['𑅁']='.', --danda
    ['𑅂']='.', --double danda
    ['𑅃']='?', -- question mark
}

function export.tr(text, lang, sc)
	if sc ~= "Cakm" then
		return nil
	end
	
	text = mw.ustring.gsub(
		text,
		'([𑄃𑄇-𑄦𑅄𑅇])'.. -- consonant
		'([𑄧-𑄴'..u(0x11145,0x11146)..']?)'.. -- vowel, joiner or no vowel
		'([𑀅-𑀒]?)', -- independent vowel 
		function(c, d, e)
			if d == "" and e ~= "" then        
				if tt[e] == "i" or tt[e] == "u" then return consonants[c] .. 'a' .. tt[e] .. '̈'
				else return consonants[c] .. 'a' .. tt[e] end
			elseif e ~= "" then
				return consonants[c] .. diacritics[d] .. tt[e]
			elseif d == "" then        
				return consonants[c] .. 'a'
			else
				return consonants[c] .. diacritics[d]
			end
		end)

	text = mw.ustring.gsub(text, '.', tt)
	if (lang == 'ccp') then
		text = mw.ustring.gsub(text, '.',
			{
				['ă']='a', ['a']='ā', ['ā']='A',
--				['ṃ']='ṅ',
				['v']='w',
				['y']='ẏ' ,['ⓨ']='y',
			})
		text = mw.ustring.gsub(text, 'ṃ$', 'ṅ')
	elseif (lang == 'pi') then
		text = mw.ustring.gsub(text, 'aḥ', 'ā')
	end
	if (lang == 'sa' or lang == 'pi') and mw.ustring.match(text, 'l̥') then
		text = mw.ustring.gsub(text, 'l̥', 'ḷ')
		text = mw.ustring.toNFC(text)
	end

	return text
end
 
return export