Jump to content

Module:Samr-translit

From Wiktionary, the free dictionary

This module will transliterate text in the Samaritan script. It is used to transliterate Samaritan Aramaic. 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:Samr-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 u = require("Module:string/char")
local ugsub = mw.ustring.gsub

local cons_list = 'ʾbgdhwbzḥṭyklmnsʿfpṣqršt'
local cons = '[' .. cons_list .. ']'

local export = {}

local tt = {
	[1] = {
		-- occlusion
		[u(0x0805, 0x0818)] = 'b',
		[u(0x0805, 0x0810)] = 'p',
	},
	[2] = {
		-- consonants
		[u(0x0800)] = 'ʾ', -- ALAF
		[u(0x0801)] = 'b', -- BIT
		[u(0x0802)] = 'g', -- GAMAN
		[u(0x0803)] = 'd', -- DALAT
		[u(0x0804)] = 'h', -- IY
		[u(0x0805)] = 'w', -- BAA
		[u(0x0806)] = 'z', -- ZEN
		[u(0x0807)] = 'ḥ', -- IT
		[u(0x0808)] = 'ṭ', -- TIT
		[u(0x0809)] = 'y', -- YUT
		[u(0x080A)] = 'k', -- KAAF
		[u(0x080B)] = 'l', -- LABAT
		[u(0x080C)] = 'm', -- MIM
		[u(0x080D)] = 'n', -- NUN
		[u(0x080E)] = 's', -- SINGAAT
		[u(0x080F)] = 'ʿ', -- IN
		[u(0x0810)] = 'f', -- FI
		[u(0x0811)] = 'ṣ', -- TSAADIY
		[u(0x0812)] = 'q', -- QUF
		[u(0x0813)] = 'r', -- RISH
		[u(0x0814)] = 'š', -- SHAN
		[u(0x0815)] = 't', -- TAAF
		-- consonant modifier
		[u(0x0816)] = 'ʿ', -- IN
		[u(0x0817)] = 'ʿ', -- IN-ALAF
		[u(0x081A)] = 'ỹ', -- MODIFIER EPENTHETIC YUT
		[u(0x081B)] = 'ỹ', -- EPENTHETIC YUT
		-- vowel signs
		[u(0x081C)] = 'ê', -- LONG E
		[u(0x081D)] = 'e', -- E
		[u(0x081E)] = 'å̂ː', -- OVERLONG AA
		[u(0x081F)] = 'å̂', -- LONG AA
		[u(0x0820)] = 'å', -- AA
		[u(0x0821)] = 'âː', -- OVERLONG A
		[u(0x0822)] = 'â', -- LONG A
		[u(0x0823)] = 'a', -- A
		[u(0x0824)] = 'ă', -- MODIFIER SHORT A
		[u(0x0825)] = 'ă', -- SHORT A
		[u(0x0826)] = 'u', -- U
		[u(0x0827)] = 'û', -- LONG U
		[u(0x0828)] = 'i', -- MODIFIER LETTER I
		[u(0x0829)] = 'î', -- LONG I
		[u(0x082A)] = 'i', -- I
		[u(0x082B)] = 'o', -- O
		[u(0x082C)] = '', -- SUKUN
		-- punctuation
		[u(0x0830)] = ' ', -- PUNCTUATION NEQUDAA
	},
	[3] = {
		-- consonant with dagesh
		['(' .. cons .. ')' .. u(0x0819)] = '%1%1',
	},
}

function export.tr(text, lang, sc)
	for _, replacements in ipairs(tt) do
		for regex, replacement in pairs(replacements) do
			text = ugsub(text, regex, replacement)
		end
	end
	
	return text
end

return export