This module will transliterate Cyrillic Tatar text per WT:TT TR through the function tr. It may not match the Latin spelling used in Tatar, just the transliteration. Г is replaced by the module with ğ and к with q after а, о, у, ы or in word start before them, otherwise they are turned into g and k.


local M={}
 
local tt={
          ["ү"]="ü",['Ү']='Ü',   ["т"]="t",['Т']='T', ["р"]="r",['Р']='R',   ["ф"]="f",['Ф']='F',
          ["ю"]="yu",['Ю']='Yu', ["ш"]="ş",['Ш']='Ş', ["ь"]="’",['Ь']='’',   ["ъ"]="ʺ",['Ъ']='ʺ', ["н"]="n",['Н']='N', 
          ["п"]="p",['П']='P',   ["й"]="y",['Й']='Y', ["л"]="l",['Л']='L',   ["з"]="z",['З']='Z', ["е"]="e",['Е']='E', 
          ["г"]="g",['Г']='G',   ["б"]="b",['Б']='B', ["у"]="u",['У']='U',   ["с"]="s",['С']='S', ["х"]="x",['Х']='X',
          ["ч"]="ç",['Ч']='Ç', ["щ"]="şç",['Щ']='Şç', ["я"]="ya",['Я']='Ya', ["ы"]="ı",['Ы']='I', ["э"]="e",['Э']='E', 
          ["м"]="m",['М']='M',   ["о"]="o",['О']='O', ["и"]="i",['И']='İ,', ["ё"]="yo",['Ё']='Yo', ["ж"]="j",['Ж']='J',
          ["к"]="k",['К']='K',   ["д"]="d",['Д']='D', ["в"]="w",['В']='W', ["ц"]="ts",['Ц']='Ts', ["а"]="a",['А']='A',
          ["ң"]="ñ",['Ң']='Ñ',   ["җ"]="c",['Җ']='C', ["һ"]="h",['Һ']='H',   ["ә"]="ä",['Ә']='Ä'
};
 
function M.tr(text)--translit any words or phrases
    if type(text) == "table" then text = text.args[1] end
 
    text = mw.ustring.gsub(
            text,   "([АОӘУЫЕЯЁЮИЕаоәуыэяёюиеъь%A][́̀]?)([Ее])",
            function(a,e) return a..(e=='е' and 'ye' or 'Ye') end
        ):gsub("^Е",'Ye'):gsub("^е",'ye'):gsub("ия$",'iyä');--not last word end handled in code end
    -- Deal with dual nature of к, г
    local t={['К']='Q',['к']='q',['Г']='Ğ',['г']='ğ'};
    text = mw.ustring.gsub(text, "(%a?)([КкГг])(.?)",function(b,c,a)
        return b .. (
            mw.ustring.match(b>'' and b or a,"[АОУЫаоуы]") and t[c] or tt[c] --in word start looks on next letter
            ) .. a
    end);
    return (mw.ustring.gsub(mw.ustring.gsub(text, "ия%A",'iyä'), '.', tt))
end
return M