Module:User:Bababashqort:kk-translit

From Wiktionary, the free dictionary
Jump to navigation Jump to search

This is a private module sandbox of Bababashqort:kk-translit, for their own experimentation. Items in this module may be added and removed at Bababashqort:kk-translit's discretion; do not rely on this module's stability.


local export = {}
local vowels = "АаЫыОоҰұӘәЕеІіӨөҮү"
local rsubn = mw.ustring.gsub

local tt = {
["А"]="A", ["а"]="a", ["Ә"]="Ä", ["ә"]="ä", ["Б"]="B", ["б"]="b", ["В"]="V", ["в"]="v", ["Г"]="G", ["г"]="g", ["Ғ"]="Ğ", ["ғ"]="ğ", 
["Д"]="D", ["д"]="d", ["Е"]="E", ["е"]="e", ["Ё"]="Yo", ["ё"]="yo", ["Ж"]="J", ["ж"]="j", ["З"]="Z", ["з"]="z", ["И"]="İy", ["и"]="iy", 
["Й"]="Y", ["й"]="y", ["К"]="K", ["к"]="k", ["Қ"]="Q", ["қ"]="q", ["Л"]="L", ["л"]="l", ["М"]="M", ["м"]="m", ["Н"]="N", ["н"]="n", 
["Ң"]="Ñ", ["ң"]="ñ", ["О"]="O", ["о"]="o", ["Ө"]="Ö", ["ө"]="ö", ["П"]="P", ["п"]="p", ["Р"]="R", ["р"]="r", ["С"]="S", ["с"]="s", 
["Т"]="T", ["т"]="t", ["У"]="W", ["у"]="uw", ["Ұ"]="U", ["ұ"]="u", ["Ү"]="Ü", ["ү"]="ü", ["Ф"]="F", ["ф"]="f", ["Х"]="H", ["х"]="h", 
["Һ"]="H", ["һ"]="h", ["Ц"]="Ts", ["ц"]="ts", ["Ч"]="Tc", ["ч"]="tc", ["Ш"]="C", ["ш"]="c", ["Щ"]="Cc", ["щ"]="cc", ["Ъ"]="", ["ъ"]="", 
["Ы"]="I", ["ы"]="ı", ["І"]="İ", ["і"]="i", ["Ь"]="", ["ь"]="", ["Э"]="E", ["э"]="e", ["Ю"]="Yu", ["ю"]="yu", ["Я"]="Ya", ["я"]="ya", 
};

-- Main translit
function export.tr(text, lang, sc)
	if type(text) == "table" then
		options = {}
		text, script = text.args[1], text.args[2]
	end
	
	if not sc then
		sc = require("Module:languages").getByCode("kk"):findBestScript(text):getCode()
	end
	
	if sc ~= "Cyrl" then
		return nil
	end
	local frontvowel = "ӘәЕеІіӨөҮү"
	local backvowel = "АаЫыОоҰұ"
	local consonant = "[^" .. vowels .. ". -]"
	
	-- decompose
	text = rsubn(text, "ё", "йо")
	text = rsubn(text, "ю", "йу")
	text = rsubn(text, "я", "йа")

	-- check preceeding vowel
	-- for w
	text = rsubn(text, "([" .. backvowel .. "])(" .. consonant .. ")у", "%1%2ыу")
	text = rsubn(text, "([" .. frontvowel .. "])(" .. consonant .. ")у", "%1%2іу")

	text = rsubn(text, "нг([^" .. vowels .. "])", "ң%1") 
	text = rsubn(text, "Нг([^" .. vowels .. "])", "Ң%1") 
	text = rsubn(text, "нг$", "ң")
	text = rsubn(text, "", "") 
	text = rsubn(text, "", "") 
	text = rsubn(text, "[Ии]([Яя])", "%1")
	--currently it is not clear how these two are romanized
	text = rsubn(text, "щ", "ш")
	text = rsubn(text, "Щ", "Ш")
	text = rsubn(text,"[ьЬ]" , "" )
	--remove them if their romanization changes
	text = rsubn(text, '.', tt)
	return text
end

return export