Jump to content

Module:kk-translit

From Wiktionary, the free dictionary

All tests passed. (refresh)

TextExpectedActualComments
test_translit_kazakh_Arab:
Passedبارلىق ادامدار تۋمىسىنان ازات جانە ٴقادىر-قاسيەتى مەن قۇقىقتارى تەڭ بولىپ دۇنيەگە كەلەدى. ادامدارعا اقىل-پاراسات، ار-وجدان بەرىلگەن، سوندىقتان ولار ٴبىر-بىرىمەن تۋىستىق، باۋىرمالدىق قارىم-قاتىناس جاساۋلارى ٴتيىس.barlıq adamdar tuwmısınan azat jäne qadir-qasiyeti men quqıqtarı teŋ bolıp düniyege keledi. adamdarğa aqıl-parasat, ar-ojdan berilgen, sondıqtan olar bir-birimen tuwıstıq, bawırmaldıq qarım-qatınas jasawları tiyis.barlıq adamdar tuwmısınan azat jäne qadir-qasiyeti men quqıqtarı teŋ bolıp düniyege keledi. adamdarğa aqıl-parasat, ar-ojdan berilgen, sondıqtan olar bir-birimen tuwıstıq, bawırmaldıq qarım-qatınas jasawları tiyis.
Passedٴتيىسtiyistiyis
Passedۋاقىتتانwaqıttanwaqıttan
Passedمادەنيmädeniymädeniy
Passedاستاناسىastanasıastanası
Passedقۋاتتىquwattıquwattı
Passedاياعىڭدىayağıŋdıayağıŋdı
Passedجۋۋjuwuwjuwuw
TextExpectedActualComments
test_translit_kazakh_Cyrl:
PassedБарлық адамдар тумысынан азат және қадір-қасиеті мен құқықтары тең болып дүниеге келеді. Адамдарға ақыл-парасат, ар-ождан берілген, сондықтан олар бір-бірімен туыстық, бауырмалдық қарым-қатынас жасаулары тиіс.Barlıq adamdar tuwmısınan azat jäne qadir-qasiyeti men quqıqtarı teŋ bolıp düniyege keledi. Adamdarğa aqıl-parasat, ar-ojdan berilgen, sondıqtan olar bir-birimen tuwıstıq, bawırmaldıq qarım-qatınas jasawları tiyis.Barlıq adamdar tuwmısınan azat jäne qadir-qasiyeti men quqıqtarı teŋ bolıp düniyege keledi. Adamdarğa aqıl-parasat, ar-ojdan berilgen, sondıqtan olar bir-birimen tuwıstıq, bawırmaldıq qarım-qatınas jasawları tiyis.
Passedтиісtiyistiyis
Passedуақыттанwaqıttanwaqıttan
Passedмәдениmädeniymädeniy
Passedастанасыastanasıastanası
Passedқуаттыquwattıquwattı
Passedаяғыңдыayağıŋdıayağıŋdı
Passedжууjuwuwjuwuw

local export = {}
local yodated_v = "ЯяЮюЁё"
local vowels = "үҮұҰеЕэЭәӘөӨАаоОЫыІі" .. "اىوۇە" .. yodated_v
local consonants = "БбВвГгҒғДдЖжЗзЙйКкҚқЛлМмНнҢңПпРрСсТтФфХхҺһЦцЧчШшЩщЪъЬь" .. "بپتجچحدرزسشعفقكگڭلمنۆھ" 
local semiv = "УуИи" .. "يۋ" .. "IiyUuw" -- these letters act irregularly so deal with them separately 
local U = mw.ustring.char
local gsub = mw.ustring.gsub
local hamzah = U(0x674) -- Kazakh High Hamza
local sukuun = U(0x652) -- sukuun is not used in Kazakh arabic orthography, its only used here to supress vowel fronting when respelling terms in quotation templates

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

	tt["Arab"] = {
 -- consonants
	["م"] = "m",  ["ن"] = "n",  ["د"] = "d",  ["ت"] = "t",
	["ب"] = "b",  ["پ"] = "p",  ["ف"] = "f",  ["ق"] = "q",
	["ك"] = "k",  ["ڭ"] = "ŋ", ["گ"] = "g",  ["ع"] = "ğ",
	["ھ"] = "h",  ["ح"] = "x",  ["چ"] = "č",
	["ج"] = "j", ["ز"] = "z",  ["س"] = "s",
	["ش"] = "š", ["ر"] = "r",  ["ل"] = "l",  
	["ي"] = "ıy",  ["ۋ"] = "uw", ["ۆ"] = "v",
	-- vowels
	["ا"] = "a", ["ە"] = "e", ["ى"] = "ı",
	["و"] = "o", ["ۇ"] = "u", [hamzah] = "", [sukuun] = "",
	-- punctuation
	["؟"]="?",
	["،"]=",",
	["؛"]=";",
	["ـ"]="-"
}

local function vowelfronting(text)
	text = gsub(text, "ا", "ä")
	text = gsub(text, "ە", "e")
	text = gsub(text, "ى", "i")
	text = gsub(text, "ي", "iy")
	text = gsub(text, "و", "ö")
	text = gsub(text, "ۇ", "ü")
	text = gsub(text, "ۋ", "üw")
	text = gsub(text, "Я", "Йә")
	text = gsub(text, "я", "йә")
	text = gsub(text, "Ё", "Йө")
	text = gsub(text, "ё", "йө")
	return text
end


function export.tr(text, lang, sc)
	if type(text) == "table" then
		options = {}
		text, script = text.args[1], text.args[2]
	end
	if (sc == "Cyrl") then
		text = gsub(text, '([юЮ])', function(c)
				local yodated = {
				["ю"]="йу",["Ю"]="Йу"}
			return yodated[c]
			end)

		text = gsub(text,
							   "([АОҰЭЯЁЮЕЪЬаоұэяёюеьъ][́̀]?)([ЕеЭэ])",
							   function(a, e)
			local iotated = {
				['е'] = 'йе', ['Е'] = 'ЙЕ',
				['э'] = 'е', ['Э'] = 'Е',	-- yodate it now bc removing it later fixes issues		
			}
			return a .. iotated[e]
							   end)

		-- add vowel
		local frontv = {
				['И'] = 'İy',
				['и'] = 'iy',
				['У'] = 'Üw',
				['у'] = 'üw',
				}
		local backv = {
				['И'] = 'Iy',
				['и'] = 'ıy',
				['У'] = 'Uw',
				['у'] = 'uw',
				}
		local defaultv = {
				['И'] = 'İy',
				['и'] = 'iy',
				['У'] = 'Uw',
				['у'] = 'uw',
				}
		
		text = gsub(text, '([^' .. consonants .. semiv .. '])([Уу])', 
			function(v, s)
				local semiv = {
				['У'] = 'W',
				['у'] = 'w',
				}
				return v .. semiv[s]
			end) 
		text = gsub(text, '^([Уу])([^' .. consonants .. '])', 
			function(s, v)
				local semiv = {
				['У'] = 'W',
				['у'] = 'w',
				}
				return semiv[s] .. v
			end) 

		-- match the fronting of the following vowel, if there is one
		text = gsub(text, '([ИиУу])([' .. vowels ..'])', 
			function(s, v)
				if mw.ustring.match(v, '[үҮеЕэЭәӘөӨІі]') then
			return frontv[s] .. v
				else
			return backv[s] .. v
				end
			end)

		-- otherwise, match the fronting of the previous vowel

		text = gsub(text, '([' .. vowels .. "КкГгҚқҒғ][" .. consonants .. semiv .. ']*)([ИиУу])', 
			function(v, s)
				if mw.ustring.match(v, '[үҮеЕэЭәӘөӨІіГгКк]') then
			return v .. frontv[s]
				else if mw.ustring.match(v, '[ұҰАаоОЫыҒғҚқ]') then
			return v .. backv[s]
					else
						return v .. defaultv[s]
					end
				end
			end)

		--[=[ EXCEPTION Каир = Kair

		this only ever happens in Russian loanwords so we wont bother with vowel harmony ]=]
	
		text = gsub(text, '([' .. vowels .. '])([Ии])([' .. consonants .. '])', 
			function(v, s, c)
				local semiv = {
				['И'] = 'İ',
				['и'] = 'i',
				}
				return v .. semiv[s] .. c
			end) 


		text = gsub(text, "([İiIı])[Yy]([ЯяЮюЁёЭэ])", "%1%2")
		text = gsub(text, "[Йй]([эЭ])", "%1")
		if mw.ustring.match(text, "[" .. vowels .. "ГгКк][" .. consonants .. semiv .. "]*[ЯяЮюЁё]") then
		text = gsub(text, "(" .. "[үҮеЕэЭәӘөӨІіГгКк]" .. "[" .. consonants .. semiv .. "ÎîÛû]*[ЯяЮюЁё])", vowelfronting) else
		text = gsub(text, "(" ..  "[ЯяЮюЁё]" .. "[" .. consonants .. semiv .. "ÎîÛû]*" .. "[үҮеЕэЭәӘөӨІіГгКк])", vowelfronting)
		end
	end

	if (sc == "Arab") then

		-- mark fronting
		text = gsub(text, U(0x621), hamzah)
		--[=[ Many government sources in China and Kazakhstan use regular hamza 
		so we'll allow it here; But ideally, it should be replaced in entries.
		]=]
		text = gsub(text, "([" .. vowels .. consonants .. semiv .. "?]+)([ەكگ])", hamzah .. "%1%2")
		text = gsub(text, "([^" .. vowels .. consonants .. semiv .. "]+)([ەكگ])", "%1" .. hamzah .. "%2")
		text = gsub(text, "^([ەكگ])", hamzah .. "%1")

		-- change ۋي in open syllables
		text = gsub(text, "([^" .. consonants .. semiv .. "])([ۋي])([" .. vowels .. "])", 
			function(c, s, v)
				local addv = {
				['ۋ'] = 'w',
				['ي'] = 'y',
				}
			return c .. addv[s] .. v
					end)
		text = gsub(text, "([" .. vowels .. "])([ۋي])", 
			function(v, s)
				local addv = {
				['ۋ'] = 'w',
				['ي'] = 'y',
				}
			return v .. addv[s]
					end)
		text = gsub(text, "^([ۋي])([^" .. consonants .. semiv .. "])", 
			function(s, c)
				local addv = {
				['ۋ'] = 'w',
				['ي'] = 'y',
				}
			return addv[s] .. c
					end)


		--[=[text = gsub(text, "([" .. consonants .. semiv .. "])([ۋي])([" .. consonants .. semiv .. "])", 
			function(c, s, v)
				local addv = {
				['ۋ'] = 'û',
				['ي'] = 'î',
				}
			return c .. addv[s] .. v
					end)
		text = gsub(text, "([^" .. vowels .. consonants .. semiv .. "])([ۋي])([" .. consonants .. semiv .. "])", 
			function(c, s, v)
				local addv = {
				['ۋ'] = 'û',
				['ي'] = 'î',
				}
			return c .. addv[s] .. v
					end)
		
		
		text = gsub(text, "^([ۋي])([" .. consonants .. "])", 
			function(s, v)
				local addv = {
				['ۋ'] = 'û',
				['ي'] = 'î',
				}
			return addv[s] .. v
					end)]=]

		-- vowel harmony
		text = gsub(text, "(" .. hamzah .. "[" .. consonants .. vowels .. semiv .. "îû]+)", vowelfronting)

		
		-- ق and ع break vowel harmony
		text = gsub(text,
							   "([قع])([äiöü])",
							   function(c, v)
			local defronted = {
				['ä'] = 'a', ['i'] = 'ı',
				['ö'] = 'o', ['ü'] = 'u', 				
			}
			return c .. defronted[v]
							   end)
		text = gsub(text,
							   "([äiöü])([قع])",
							   function(v, c)
			local defronted = {
				['ä'] = 'a', ['i'] = 'ı',
				['ö'] = 'o', ['ü'] = 'u', 				
			}
			return defronted[v] .. c
							   end)
		
	end
    return mw.ustring.toNFC(mw.ustring.gsub(text, '.', tt[sc]))
end

return export