Module:Ital-translit

From Wiktionary, the free dictionary
Jump to navigation Jump to search

This module will transliterate text in the Old Italic script. It is used to transliterate Etruscan, North Picene, Oscan, South Picene, Camunic, Faliscan, Lemnian, Lepontic, Raetic, Umbrian, and Venetic. 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:Ital-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 = {}

-- Standard transcription
local common_rules = {
	['𐌀'] = 'a',
	['𐌁'] = 'b',
	['𐌂'] = 'c',
	['𐌃'] = 'd',
	['𐌄'] = 'e',
	['𐌅'] = 'v',
	['𐌆'] = 'z',
	['𐌇'] = 'h',
	['𐌈'] = 'θ',
	['𐌉'] = 'i',
	['𐌊'] = 'k',
	['𐌋'] = 'l',
	['𐌌'] = 'm',
	['𐌍'] = 'n',
	['𐌎'] = 'š',
	['𐌏'] = 'o',
	['𐌐'] = 'p',
	['𐌑'] = 'ś',
	['𐌒'] = 'q',
	['𐌓'] = 'r',
	['𐌔'] = 's',
	['𐌕'] = 't',
	['𐌖'] = 'u',
	['𐌗'] = 'x',
	['𐌘'] = 'φ',
	['𐌙'] = 'χ',
	['𐌚'] = 'f',
	['𐌛'] = 'ř',
	['𐌜'] = 'ç',
	['𐌝'] = 'í',
	['𐌞'] = 'ú',
	['𐌟'] = 'ś',
	-- Numerals
	['𐌠'] = 'Ⅰ',
	['𐌡'] = 'Ⅴ',
	['𐌢'] = 'Ⅹ',
	['𐌣'] = 'Ⅼ',
	-- Punctuation
	['·'] = ' ',
	['⁚'] = ' ',
	['⁝'] = ' ',
}

local lang_rules = {
	-- Etruscan
	['ett'] = {
		['𐌟'] = 'Ⅽ',
	},

	-- Old Latin
	['itc-ola'] = {
		['𐌅'] = 'f',
	},

	-- Noric
	['nrc'] = {
		['𐌂'] = 'g',
		['𐌈'] = 'd',
		['𐌙'] = 'g',
	},

	-- North Picene
	['nrp'] = {
		['𐌂'] = 'g',
	},

	-- Oscan
	['osc'] = {
		['𐌂'] = 'g',
	},

	-- South Picene
	['spx'] = {
		['𐌂'] = 'g',
		['𐌑'] = 'í',
	},

	-- Camunic
	['xcc'] = {
		['𐌁'] = 'ś',
		['𐌂'] = 'g',
		['𐌑'] = 'b',
		['𐌙'] = 's',
		['𐌟'] = 'þþ',
		['𐌣'] = 'þ',
	},

	-- Faliscan
	['xfa'] = {
		['𐌅'] = 'f', -- looks more like an up-arrow, but this is how it should be encoded
	},

	-- Raetic
	['xrr'] = {
		['𐌁'] = 'þ',
		['𐌂'] = '?',
	},

	-- Umbrian
	['xum'] = {
		['𐌑'] = 's',
	},

	-- Venetic
	['xve'] = {
		['𐌂'] = 'j',
		['𐌆'] = 'd',
		['𐌘'] = 'b',
		['𐌙'] = 'g',
	},
}

function export.tr(text, lang, sc)
	-- If the script is not Ital, do not transliterate
	if sc ~= "Ital" then
		return
	end

	-- Transliterate language-specific exceptions
	if lang == "xve" then
		text = mw.ustring.gsub(text, '𐌇𐌅', 'f')
	end

	if lang_rules[lang] then
		text = mw.ustring.gsub(text, '.', lang_rules[lang])
	end

	-- Transliterate remaining characters
	text = mw.ustring.gsub(text, '.', common_rules)

	return text
end

return export