Pergi ke kandungan

Modul:dar-translit

Daripada Wikikamus

Modul ini akan mentransliterasi Bahasa Dargwa teks. Ia juga digunakan untuk mentransliterasi bahasa Kaitag. 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:dar-translit/testcases.

Functions

[sunting]
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 mapping1 = {
	["б"]="b", ["п"]="p", ["ф"]="f", ["в"]="v", ["м"]="m",
	["д"]="d", ["т"]="t", ["й"]="j", ["н"]="n", ["з"]="z", ["ц"]="c",
	["с"]="s", ["ж"]="ž", ["ш"]="š", ["щ"]="šč",
	["л"]="l", ["ч"]="č", ["р"]="r", ["г"]="g", ["к"]="k", ["х"]="χ", 
	["ъ"]="ʾ", ["а"]="a", ["е"]="e", ["ы"]="y", ["и"]="i", ["о"]="o", ["у"]="u", 
	["ё"]="ë", ["ь"]="’", ["э"]="e", ["ю"]="ju", ["я"]="ə",
	["Б"]="B", ["П"]="P", ["Ф"]="F", ["В"]="V", ["М"]="M",
	["Д"]="D", ["Т"]="T", ["Й"]="J", ["Н"]="N", ["З"]="Z", ["Ц"]="C",
	["С"]="S", ["Ж"]="Ž", ["Ш"]="Š", ["Щ"]="Šč",
	["Л"]="L", ["Ч"]="Č", ["Р"]="R", ["Г"]="G", ["К"]="K", ["Х"]="Χ", 
	["Ъ"]="ʾ", ["А"]="A", ["Е"]="E", ["Ы"]="Y", ["И"]="I", ["О"]="O", ["У"]="U", 
	["Ё"]="Ë", ["Ь"]="’", ["Э"]="E", ["Ю"]="Ju", ["Я"]="Ə"
}

local mapping2 = {
	['дз'] = 'ʒ', ['Дз'] = 'Ʒ', ['дж'] = 'ǯ', ['Дж'] = 'Ǯ',
	['пӏ'] = 'ṗ', ['Пӏ'] = 'Ṗ', ['цӏ'] = 'c̣', ['тӏ'] = 'ṭ',
	['чӏ'] = 'č̣', ['кь'] = 'q̇', ['кӏ'] = 'ḳ', ['хь'] = 'x',
	['хъ'] = 'q', ['къ'] = 'ɢ', ['гъ'] = 'γ', ['гӏ'] = 'ʿ',
	['хӏ'] = 'ḥ', ['гь'] = 'h', ['Цӏ'] = 'C̣', ['Тӏ'] = 'Ṭ',
	['Сс'] = 'S̄', ['Чӏ'] = 'Č̣', ['Кь'] = 'Q̇', ['Кӏ'] = 'Ḳ',
	['Хь'] = 'X', ['Хъ'] = 'Q', ['Къ'] = 'ɢ', ['Гъ'] = 'Γ',
	['Гӏ'] = 'ʿ', ['Хӏ'] = 'Ḥ', ['Гь'] = 'H',
}

function export.tr(text, lang, sc)
	for pat, repl in pairs(mapping2) do
		text = mw.ustring.gsub(text, pat, repl)
	end
	
	text = mw.ustring.gsub(text, '.', mapping1)
	
	return text
end

return export