模組:Kxv-translit

維基詞典,自由的多語言詞典

這個模組將轉寫庫維語的文字。 最好不要直接從模板或其他模組呼叫此模組;要從模板中使用它, 請使用{{xlit}}; 要從模組中使用它,請使用Module:languages#Language:transliterate

關於測試用例,請見Module:Kxv-translit/testcases

函式

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 consonants = {
	--common
	["କ"]="k", ["ଖ"]="kh", ["ଗ"]="g", ["ଘ"]="gh", ["ଙ"]="ṅ",
	["ଚ"]="c", ["ଛ"]="ch", ["ଜ"]="j", ["ଝ"]="jh", ["ଞ"]="ñ", 
	["ଟ"]="ṭ", ["ଠ"]="ṭh", ["ଡ"]="ḍ", ["ଢ"]="ḍh", ["ଣ"]="ṇ", 
	["ତ"]="t", ["ଥ"]="th", ["ଦ"]="d", ["ଧ"]="dh", ["ନ"]="n", 
	["ପ"]="p", ["ଫ"]="ph", ["ବ"]="b", ["ଭ"]="bh", ["ମ"]="m",
	["ଯ"]="j", ["ୟ"]="y", ["ର"]="r", ["ଲ"]="l", ["ଳ"]="ḷ",
	["ଵ"]="v", ["ୱ"]="w", ["ଶ"]="ś", ["ଷ"]="ṣ", ["ସ"]="s", ["ହ"]="h",
	--nuktas
	["କ଼"]="q", ["ଖ଼"]="x", ["ଗ଼"]="ġ", ["ଜ଼"]="z", ["ଝ଼"]="ź",
	["ଡ଼"]="ṛ", ["ଢ଼"]="ṛh", ["ଫ଼"]="f",
}

local diacritics = {
	["ା"]="a", ["ି"]="i", ["ୀ"]="ī", ["ୁ"]="u", ["ୂ"]="ū", ["ୃ"]="ru", ["ୄ"]="rū", 
	["ୢ"]="lu", ["ୣ"]="lū", ["େ"]="e", ["ୈ"]="ai", ["ୖ"]="ai", ["ୋ"]="o", ["ୌ"]="au", ["ୗ"]="au",
	["୍"]="",
}

local tt = {
	-- vowels
	["ଅ"]="o", ["ଆ"]="a", ["ଇ"]="i", ["ଈ"]="ī", ["ଉ"]="u", ["ଊ"]="ū", ["ଋ"]="ru", ["ୠ"]="rū",
	["ଌ"]="lu", ["ୡ"]="lū", ["ଏ"]="e", ["ଐ"]="ai", ["ଓ"]="o", ["ଔ"]="au",
	-- chandrabindu    
	["ଁ"]="̃", --until a better method is found
	-- anusvara    
	["ଂ"]="ṁ", --until a better method is found
	-- visarga    
	["ଃ"]="ʔ",
	-- avagraha
	["ଽ"]="’",
	--numerals
	["୦"]="0", ["୧"]="1", ["୨"]="2", ["୩"]="3", ["୪"]="4", ["୫"]="5", ["୬"]="6", ["୭"]="7", ["୮"]="8", ["୯"]="9",
	["୲"]="¼", ["୳"]="½", ["୴"]="¾", ["୵"]="¹⁄₁₆", ["୶"]="⅛", ["୷"]="³⁄₁₆",
	--punctuation        
	["।"]=".", --danda
}

function export.tr(text, lang, sc)
	text = gsub(
		text,
		"([କଖଗଘଙଚଛଜଝଞଟଠଡଢଣତଥଦଧନପଫବଵଭମଯୟରଲଳୱଶଷସହ]଼?)"..
		"([ାିୀୁୂୃୄେୈୖୋୌୗ୍ୢୣ]?)",
		function(c, d)
			if not consonants[c] then
				return c
			end
			if d == "" then
				return consonants[c] .. "o"
			else
				return consonants[c] .. diacritics[d]
			end
		end)

	text = mw.ustring.gsub(text, ".", tt)
	
	-- anusvara
	text = gsub(text, 'ṁ([kqxgġṅ])', 'ṅ%1')
	text = gsub(text, 'ṁ([cjźñ])', 'ñ%1')
	text = gsub(text, 'ṁ([ṭḍṇ])', 'ṇ%1')
	text = gsub(text, 'ṁ([tdnz])', 'n%1')
	text = gsub(text, 'ṁ([pfbm])', 'm%1')

	-- long vowels
	text = gsub(text, '([oaāiue])%1', '%1̄') -- VV → V̄ 
	text = gsub(text, '([oea])୕', '%1̄')
	text = gsub(text, 'oa', 'ā') 
	text = gsub(text, 'aā', 'ā')

	return mw.ustring.toNFC(text)
	
end
 
return export