Module:crdc-translit: Difference between revisions

From Linguifex
Jump to navigation Jump to search
Nehster9 (talk | contribs)
Created page with "local export = {} local tt = {} tt["Deva"] = { {"क", "k"}, {"ख", "kh"}, {"ग", "g"}, {"ङ", "ng"}, {"ष", "ṣ"}, {"न", "n"}, {"ा", "ā"}, } tt["Latn"] = require("Module:table").invert(tt["Deva"]) function export.tr(text, lang, sc) text = mw.ustring.lower(text) for _, rule in ipairs(tt[sc]) do text = mw.ustring.gsub(text, rule[1], rule[2]) end return text end function export.template_tr(frame) local args = require("Module:parameters")..."
 
Nehster9 (talk | contribs)
No edit summary
 
Line 1: Line 1:
local export = {}
local export = {}


local tt = {}
local consonants = {
tt["Deva"] = {
['क'] = 'k', ['ख'] = 'kh', ['ग'] = 'g', ['ङ'] = 'ṅ',
{"क", "k"},
['च'] = 'c', ['छ'] = 'ch', ['ज'] = 'j', ['ञ'] = 'ñ',
{"ख", "kh"},
['ट'] = 'ṭ', ['ठ'] = 'ṭh', ['ड'] = 'ḍ', ['ण'] = 'ṇ',
{"ग", "g"},
['त'] = 't', ['थ'] = 'th', ['द'] = 'd', ['न'] = 'n',
{"ङ", "ng"},
['प'] = 'p', ['फ'] = 'ph', ['ब'] = 'b', ['म'] = 'm',
{"", "ṣ"},
['य'] = 'y', ['र'] = 'r', ['ल'] = 'l', ['व'] = 'w',
{"न", "n"},
['श'] = 'ś', [''] = 'ṣ', ['स'] = 's', ['ह'] = 'h',
['च़'] = 'ċ', ['छ़'] = 'ċh', ['ज़'] = 'z',['फ़']='f',
{"", "ā"},
['क़'] = 'q', ['ख़'] = 'x', ['ग़'] = 'ġ',
['भ'] = 'bh', --found ocassionally in some Sanskrit loanwords
}
 
local diacritics = {
[''] = 'ā', ['ॅ'] = 'ạ', ['ॉ'] = 'ạ̄', ['ॖ'] = 'ụ', ['ॗ'] = 'ụ̄', ['ि'] = 'i', ['ी'] = 'ī', ['ु'] = 'u', ['ू'] = 'ū', ['ृ'] = 'ṛ',
['ॆ'] = 'e', ['े'] = 'ē', ['ै'] = 'ai', ['ॊ'] = 'o', ['ो'] = 'ō', ['ॏ'] = 'ô', ['ौ'] = 'au', ['्'] = '',['ऺ'] = 'ạ', ['ऻ']='ạ̄'
}
}


tt["Latn"] = require("Module:table").invert(tt["Deva"])
local tt = {
-- vowels
['अ'] = 'a', ['आ'] = 'ā', ['ॲ'] = 'ạ', ['ऑ'] = 'ạ̄', ['ॶ'] = 'ụ', ['ॷ'] = 'ụ̄', ['इ'] = 'i', ['ई'] = 'ī', ['उ'] = 'u', ['ऊ'] = 'ū', ['ऋ'] = 'ṛ',
['ऎ'] = 'e', ['ए'] = 'ē', ['ऐ'] = 'ai', ['ऒ'] = 'o', ['ओ'] = 'ō', ['ॵ'] = 'ô', ['औ'] = 'au', ['ॳ'] = 'ạ', ['ॴ']=  'ạ̄',
--chandrabindu
['ँ'] = 'm̐', --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
['॥'] = '.', --double danda
['ॐ'] = 'om',
}


function export.tr(text, lang, sc)
function export.tr(text, lang, sc)
text = mw.ustring.lower(text)
text = mw.ustring.gsub(text, '(.[]?.[़]?)$', '%1्')
text = mw.ustring.gsub(text,
for _, rule in ipairs(tt[sc]) do
'([कखगघङचछजझञटठडढणतथदधनपफबभमयरलळवशषसहक़ख़]़?)' .. --tbd later
text = mw.ustring.gsub(text, rule[1], rule[2])
'([ािॅॉीुॖॗूृॄॢॣेैोौ्ॆॉॊौॏऺऻ]?)',
end
function(c, d)
 
if d == "" then
    return text
return consonants[c] .. 'a'
end
else
 
return consonants[c] .. diacritics[d]
function export.template_tr(frame)
end
local args = require("Module:parameters").process(frame.args, {
end)
[1] = {required = true}, -- text
[2] = {required = true, default = "hort"},
["sc"] = {default = require("Module:scripts").findBestScriptWithoutLang(frame.args[1])}
})
local tr = export.tr(args[1], "hort", args.sc)
text = mw.ustring.gsub(text, '.', tt)
text = mw.ustring.gsub(text, '्$', '')
return tr or "-"
return text
end
end


return export
return export

Latest revision as of 05:16, 6 July 2026


This module will transliterate Cerdic 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:crdc-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 consonants = {
	['क'] = 'k', ['ख'] = 'kh', ['ग'] = 'g', ['ङ'] = 'ṅ',
	['च'] = 'c', ['छ'] = 'ch', ['ज'] = 'j', ['ञ'] = 'ñ',
	['ट'] = 'ṭ', ['ठ'] = 'ṭh', ['ड'] = 'ḍ', ['ण'] = 'ṇ',
	['त'] = 't', ['थ'] = 'th', ['द'] = 'd', ['न'] = 'n',
	['प'] = 'p', ['फ'] = 'ph', ['ब'] = 'b', ['म'] = 'm',
	['य'] = 'y', ['र'] = 'r', ['ल'] = 'l', ['व'] = 'w',
	['श'] = 'ś', ['ष'] = 'ṣ', ['स'] = 's', ['ह'] = 'h',
	['च़'] = 'ċ', ['छ़'] = 'ċh', ['ज़'] = 'z',['फ़']='f',
	['क़'] = 'q', ['ख़'] = 'x', ['ग़'] = 'ġ',
	['भ'] = 'bh', --found ocassionally in some Sanskrit loanwords
}

local diacritics = {
	['ा'] = 'ā', ['ॅ'] = 'ạ', ['ॉ'] = 'ạ̄', ['ॖ'] = 'ụ', ['ॗ'] = 'ụ̄', ['ि'] = 'i', ['ी'] = 'ī', ['ु'] = 'u', ['ू'] = 'ū', ['ृ'] = 'ṛ',
	['ॆ'] = 'e', ['े'] = 'ē', ['ै'] = 'ai', ['ॊ'] = 'o', ['ो'] = 'ō', ['ॏ'] = 'ô', ['ौ'] = 'au', ['्'] = '',['ऺ'] = 'ạ', ['ऻ']='ạ̄'
}

local tt = {
	-- vowels
	['अ'] = 'a', ['आ'] = 'ā', ['ॲ'] = 'ạ', ['ऑ'] = 'ạ̄', ['ॶ'] = 'ụ', ['ॷ'] = 'ụ̄', ['इ'] = 'i', ['ई'] = 'ī', ['उ'] = 'u', ['ऊ'] = 'ū', ['ऋ'] = 'ṛ',
	['ऎ'] = 'e', ['ए'] = 'ē', ['ऐ'] = 'ai', ['ऒ'] = 'o', ['ओ'] = 'ō', ['ॵ'] = 'ô', ['औ'] = 'au', ['ॳ'] = 'ạ',	['ॴ']=  'ạ̄',
	--chandrabindu
	['ँ'] = 'm̐', --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
	['॥'] = '.', --double danda
	['ॐ'] = 'om',
}

function export.tr(text, lang, sc)
	text = mw.ustring.gsub(text, '(.[़]?.[़]?)$', '%1्')
	text = mw.ustring.gsub(text,
		'([कखगघङचछजझञटठडढणतथदधनपफबभमयरलळवशषसहक़ख़]़?)' .. --tbd later
				'([ािॅॉीुॖॗूृॄॢॣेैोौ्ॆॉॊौॏऺऻ]?)',
		function(c, d)
			if d == "" then
				return consonants[c] .. 'a'
			else
				return consonants[c] .. diacritics[d]
			end
		end)
	
	text = mw.ustring.gsub(text, '.', tt)
	text = mw.ustring.gsub(text, '्$', '')
	
	return text
end

return export