This module will transliterate Tatar language text per WT:TT TR. This may not match the Latin spelling used in Tatar. Г is replaced by the module with ğ and к with q after а, о, у, ы or in word start before them, otherwise they are turned into g and k (only works for the preceding vowels) per WT:TT 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:tt-translit/testcases.
tr(text, lang, sc)
text
written in the script specified by the code sc
, and language specified by the code lang
.nil
.local export = {}
local rsubn = mw.ustring.gsub
-- version of rsubn() that discards all but the first return value
local function rsub(term, foo, bar)
local retval = rsubn(term, foo, bar)
return retval
end
-- apply rsub() repeatedly until no change
local function rsub_repeatedly(term, foo, bar)
while true do
local new_term = rsub(term, foo, bar)
if new_term == term then
return term
end
term = new_term
end
end
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 export.tr(text, lang, sc)
text = rsub(
text,
"(?)()",
function(a,e) return a..(e=='е' and 'ye' or 'Ye') end
)
-- ү/у should be transliterated as w after vowels (except у/ү itself)
text = rsub_repeatedly(text, "()", "%1w")
text = rsub_repeatedly(text, "()()", "%1w%2")
text = rsub(text, "^Е", "Ye")
text = rsub(text, "^е","ye")
text = rsub(text, "ия$", "iyä") --not last word end handled in code end
-- Deal with dual nature of к, г, transliterated either to "front" variants
-- k/g or "back" variants q/ğ. The back variants occur before hard signs
-- (Ъ/ъ), which then disappear, and also in the vicinity of the back vowels
-- а/о/у/ы (and their capital equivalents А/О/У/Ы). The code below that
-- handles this appears to say that the sound of word-initial к/г is
-- determined by the following vowel, and the sound of non-word-initial
-- к/г is determined by the preceding vowel. FIXME: Not sure if this is
-- correct.
-- glottal stop
text = rsub(text, "()()", "%1'")
local t = {='Q',='q',='Ğ',='ğ'}
text = rsub(text, "()()", function(a,b) return t end)
text = rsub(text,
"(%a?)()(.?)",
function(b,c,a)
return b .. (mw.ustring.match(b>'' and b or a,"") and t or tt) .. a
end
)
text = rsub(text, "ия%A", "iyä")
text = rsub(text, ".", tt)
return text
end
return export