Module:tevo-translit: Difference between revisions

From Linguifex
Jump to navigation Jump to search
Melinoë (talk | contribs)
No edit summary
Melinoë (talk | contribs)
No edit summary
Line 123: Line 123:
text = gsub(text, "ः॑","́h")
text = gsub(text, "ः॑","́h")
text = gsub(text, "ॆ॑","éi")
text = gsub(text, "","éi")
text = gsub(text, "े॑","ḗi")
text = gsub(text, "ēí","ḗi")
text = gsub(text, "ॊ॑","óu")
text = gsub(text, "","óu")
text = gsub(text, "ो॑","ṓu")
text = gsub(text, "ōú","ṓu")
text = gsub(text, '([aअ][' .. acute .. grave .. ']?[इउ])', '%1' .. diaeresis)
text = gsub(text, '([aअ][' .. acute .. grave .. ']?[इउ])', '%1' .. diaeresis)
text = gsub(text, '.', tt)
text = gsub(text, '.', tt)

Revision as of 20:42, 3 June 2026


This module will transliterate Ancient Tevvic 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:tevo-translit/testcases.

Functions

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 m_str_utils = require("Module:string utilities")

local gsub = m_str_utils.gsub
local toNFC = mw.ustring.toNFC
local U = m_str_utils.char

local grave = U(0x300)
local acute = U(0x301)
local diaeresis = U(0x308)
local svar = U(0x951)
local anud = U(0x952)
local d_svar = U(0x1CDA) -- double svarita, sometimes used for long vowel with svarita

local consonants = {
	['क']='k', 
	['ख']='kh', 
	['ग']='g', 
	['घ']='gh', 
	['च']='c', 
	['छ']='ch', 
	['ज']='j', 
	['झ']='jh', 
	['ञ']='ñ',
	['श']='ś',
	['झ़']='ź',
	['ट']='ṭ', 
	['ठ']='ṭh', 
	['ड']='ḍ', 
	['ढ']='ḍh', 
	['ण']='ṇ', 
	['ष']='ṣ',
	['ढ़']='ẓ',
	['त']='t', 
	['थ']='th', 
	['द']='d', 
	['ध']='dh', 
	['न']='n', 
	['स']='s',
	['ज़']='z',
	['प']='p', 
	['फ']='ph', 
	['ब']='b', 
	['भ']='bh', 
	['म']='m',
	['य']='y', 
	['र']='r', 
	['ल']='l', 
	['व']='v', 
	['ह']='h',
}

local diacritics = {
	['ा']='ā', 
	['ि']='i', 
	['ी']='ī', 
	['ु']='u', 
	['ू']='ū', 
	['ॆ']='ei',
	['े']='ēi', 
	['ॅ']='e',
	['ै']='ē', 
	['ॊ']='ou',
	['ो']='ōu', 
	['ॉ']='o',
	['ौ']='ō',  
	['्']='',
}

local tt = {
	-- vowels
	['अ']='a', 
	['आ']='ā', 
	['इ']='i',
	['ई']='ī', 
	['उ']='u', 
	['ऊ']='ū', 
	['ऎ']='ei',
	['ए']='ēi', 
	['ऍ']='e',
	['ऐ']='ē', 
	['ऒ']='ou',
	['ओ']='ōu', 
	['ऑ']='o',
	['औ']='ō', 
	-- anusvara
	['ं']='̣',
	-- visarga
	['ः']='h',
	-- avagraha
	['ऽ']='ʼ',
	['़']='',
	--numerals
	['०']='0', ['१']='1', ['२']='2', ['३']='3', ['४']='4', ['५']='5', ['६']='6', ['७']='7', ['८']='8', ['९']='9',
	['॒']='́',
	['॑']='́',
	--punctuation        
--  ['॥']='.', --double danda
--	['।']='.', --danda
    --Om
    ['ॐ']='oṃ',
    --reconstructed
--  ['*'] = '',
}

function export.tr(text, lang, sc)
	if sc ~= "Deva" then
		return nil
	end
		text = gsub(text,'([क-ह]़?)'..'([ािीुूृॄॢॣेैोौ्ॅॆॊॉ]?)'..'([अ-औ]?)',function(c, d, e)
			if d == "" and e ~= "" then        
				if tt[e] == "i" or tt[e] == "u" then return consonants[c] .. 'a' .. tt[e] .. diaeresis
				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 = gsub(text, "ः॑","́h")
	text = gsub(text, "eí","éi")
	text = gsub(text, "ēí","ḗi")
	text = gsub(text, "oú","óu")
	text = gsub(text, "ōú","ṓu")
	text = gsub(text, '([aअ][' .. acute .. grave .. ']?[इउ])', '%1' .. diaeresis)
	text = gsub(text, '.', tt)
	text = gsub(text, 'a([iu])([' .. acute .. grave .. '])', 'a%2%1')
	text = gsub(text, " ?[।॥]", ".")
	text = gsub(text, "(ā" .. acute .. "3[iu])" .. acute, "%1") -- for pluti vowels
	text = toNFC(text)
	
	return text
end

return export