Module:mn-translit

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

This module will transliterate Mongolian language text per WT:MN TR.

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:mn-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 trfunc = {}
 
local tt_Cyrl = {
	["Щ"]="Šč", ['щ']='šč', ["Ы"]="Y", ['ы']='y', ["Э"]="E" ,['э']='e' , ["Я"]="Ja",['я']='ja', ["У"]="U",['у']='u', ["С"]="S" ,['с']='s',
	["Ч"]="Č" , ['ч']='č' , ["Х"]="H", ['х']='h', ["Ж"]="Ž" ,['ж']='ž' , ["Д"]="D" ,['д']='d' , ["В"]="V",['в']='v', ["А"]="A" ,['а']='a',
	["М"]="M" , ['м']='m' , ["О"]="O", ['о']='o', ["И"]="I" ,['и']='i' , ["К"]="K" ,['к']='k' , ["Ш"]="Š",['ш']='š', ["Ъ"]="ʺ" ,['ъ']='ʺ',
	["Ё"]="Jo", ['ё']='jo', ["Ь"]="ʹ", ['ь']='ʹ', ["Ю"]="Ju",['ю']='ju', ["Т"]="T" ,['т']='t' , ["Р"]="R",['р']='r', ["Ц"]="Ts",['ц']='ts',
	["Ф"]="F" , ['ф']='f' , ["З"]="Z", ['з']='z', ["Е"]="E" ,['е']='e' , ["Г"]="G" ,['г']='g' , ["Б"]="B",['б']='b', ["Н"]="N" ,['н']='n',
	["П"]="P" , ['п']='p' , ["Й"]="J", ['й']='j', ["Л"]="L" ,['л']='l' , ["Ү"]="Ü" ,['ү']='ü' , ["Ө"]="Ö",['ө']='ö'
}
 
function trfunc.Cyrl(text)
	text = mw.ustring.gsub(text, "([АОУЫЕЯЁЮИЕЪЬаоуыэяёюиеъь%A][\204\129\204\128]?)([Ее])",
		function (a, e)
			return a .. (e == 'е' and 'je' or 'Je')
		end):gsub("^Е",'Je'):gsub("^е",'je')
	return (mw.ustring.gsub(text, '.', tt_Cyrl))
end
 
function trfunc.Mong(text)
	-- TODO
	return nil
end
 
function export.tr(text, lang, sc)
	if not sc then
		local m_utilities = require('Module:utilities')
		sc = m_utilities.detect_script(text, require("Module:languages").getLanguageByCode("mn"))
	end
 
	if trfunc[sc] then
		return trfunc[sc](text)
	end
end
 
return export