Module:yah-translit

This module will transliterate Yazghulami 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:yah-translit/testcases.

Functions edit

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 tt = {
	["а"] = "a", ["А"] = "A",
	["ā"] = "ā", ["Ā"] = "Ā",
	["б"] = "b", ["Б"] = "B",
	["в"] = "v", ["В"] = "V",
	["г"] = "g", ["Г"] = "G",
	["ѓ"] = "ǵ", ["Ѓ"] = "Ǵ",
	["ғ"] = "ɣ", ["Ғ"] = "Ɣ",
	["д"] = "d", ["Д"] = "D",
	["е"] = "e", ["Е"] = "E",
	["ә"] = "ə", ["Ә"] = "Ə",
	["ж"] = "ž", ["Ж"] = "Ž",
	["з"] = "z", ["З"] = "Z",
	["и"] = "i", ["И"] = "I",
	["й"] = "y", ["Й"] = "Y",
	["к"] = "k", ["К"] = "K",
	["ќ"] = "ḱ", ["Ќ"] = "Ḱ",
	["қ"] = "q", ["Қ"] = "Q",
	["л"] = "l", ["Л"] = "L",
	["м"] = "m", ["М"] = "M",
	["н"] = "n", ["Н"] = "N",
	["о"] = "o", ["О"] = "O",
	["п"] = "p", ["П"] = "P",
	["р"] = "r", ["Р"] = "R",
	["с"] = "s", ["С"] = "S",
	["т"] = "t", ["Т"] = "T",
	["у"] = "u", ["У"] = "U",
	["ф"] = "f", ["Ф"] = "F",
	["х"] = "x", ["Х"] = "X",
	["ҳ"] = "h", ["Ҳ"] = "H",
	["ц"] = "c", ["Ц"] = "C",
	["ч"] = "č", ["Ч"] = "Č",
	["ҷ"] = "ǰ", ["Ҷ"] = "J̌",
	["ш"] = "š", ["Ш"] = "Š",
	["э"] = "e", ["Э"] = "E",
}

local mapping = {
	["а̄"] = "ā", ["А̄"] = "Ā",
	["в̌"] = "w", ["В̌"] = "W",
	["д̌"] = "δ", ["Д̌"] = "Δ",
	["ѓ"] = "ǵ", ["Ѓ"] = "Ǵ",
	["й"] = "y", ["Й"] = "Y",
	["ќ"] = "ḱ", ["Ќ"] = "Ḱ",
	["т̌"] = "θ", ["Т̌"] = "Θ",
}

function export.tr(text, lang, sc)
	if sc == "Latn" then
		return nil
	end
	
	for char, translit in pairs(mapping) do
		text = mw.ustring.gsub(text, char, translit)
	end
	
	text = mw.ustring.gsub(text, '.', tt)
	
	return text
end

return export