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',
	['๐Œ›'] = 'ล™',
	['๐Œœ'] = 'รง',
	['๐Œ'] = 'รญ',
	['๐Œž'] = 'รบ',
	['๐ŒŸ'] = 'k',
	-- 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