Module:ug-translit

Definition from Wiktionary, the free dictionary
Jump to: navigation, search
The following documentation is located at Module:ug-translit/documentation. [edit]

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

Functions[edit]

tr(text, lang, sc)
Transliterates a given piece of text written in the script specified by sc, and language specified by lang. When the transliteration fails, returns nil.

local export = {}
 
local UEYtoULYtable = {
	-- consonants
	["م"] = "m",  ["ن"] = "n",  ["د"] = "d",  ["ت"] = "t",
	["ب"] = "b",  ["پ"] = "p",  ["ف"] = "f",  ["ق"] = "q",
	["ك"] = "k",  ["ڭ"] = "ng", ["گ"] = "g",  ["غ"] = "gh",
	["ھ"] = "h",  ["خ"] = "x",  ["چ"] = "ch", ["ج"] = "j",
	["ژ"] = "zh", ["ز"] = "z",  ["س"] = "s",  ["ش"] = "sh",
	["ر"] = "r",  ["ل"] = "l",  ["ئ"] = "'",
	["ي"] = "y",  ["ۋ"] = "w",
	-- vowels
	["ا"] = "a", ["ە"] = "e", ["ې"] = "ë", ["ى"] = "i",
	["و"] = "o", ["ۆ"] = "ö", ["ۇ"] = "u", ["ۈ"] = "ü",
	-- punctuation
	["؟"]="?",
	["،"]=",",
	["؛"]=";"
}
 
function export.tr(text, lang, sc)
	-- transliterate from UEY to ULY
	-- remove initial hamza
	text = mw.ustring.gsub(text, "^\216\166(.)", "%1")
	text = mw.ustring.gsub(text, "%s\216\166(.)", " %1")
	-- transliterate letters one to one
	text = mw.ustring.gsub(text, ".", UEYtoULYtable)
 
	return text
end
 
return export