This module will transliterate Ukrainian language text per WT:UK 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:uk-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 m_str_utils = require("Module:string utilities")
local rsubn = m_str_utils.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
local regular_tt = {
='A', ='a', ='B', ='b', ='V', ='v', ='H', ='h',
='G', ='g', ='D', ='d', ='E', ='e', ='Je', ='je',
='Ž', ='ž', ='Z', ='z', ='Y', ='y', ='I', ='i',
='Ji', ='ji', ='J', ='j', ='K', ='k', ='L', ='l',
='M', ='m', ='N', ='n', ='O', ='o', ='P', ='p',
='R', ='r', ='S', ='s', ='T', ='t', ='U', ='u',
='F', ='f', ='X', ='x', ='C', ='c', ='Č', ='č',
='Š', ='š', ='Šč', ='šč', ='ʹ', ='ʹ', ='Ju', ='ju',
='Ja', ='ja',
-- right single quotation mark, modifier letter apostrophe → modifier letter double prime
='ʺ', = 'ʺ',
-- Ukrainian style quotes
='“', ='”',
-- Special char used in ]
='ᵣ',
}
-- These need to be separated from the `regular_tt` so they don't interfere with reverse translit.
local obsolete_tt = {
-- obsolete letters, pre-refom
='Ë', ='ë', ='ʺ', ='ʺ', ='Y', ='y', ='I', ='i',
='È', ='è', ='J', ='j',
-- obsolete letters, Middle Ukrainian
='Je', ='je', ='ʺ', ='ʺ', ='Y', ='y', ='I', ='i',
='Ja', ='ja', ='Ja', ='ja', ='U', ='u', ='Ju', ='ju',
='Ks', ='ks', ='Ps', ='ps', ='F', ='f', ='I', ='i',
='O', ='o',
}
local AC = m_str_utils.char(0x0301) -- acute = ́
local acute_decomposer = {
= "a" .. AC,
= "e" .. AC,
= "i" .. AC,
= "o" .. AC,
= "u" .. AC,
= "y" .. AC,
= "A" .. AC,
= "E" .. AC,
= "I" .. AC,
= "O" .. AC,
= "U" .. AC,
= "Y" .. AC,
}
function export.tr(text, lang, sc)--translit any words or phrases
-- Remove word-final hard sign, either utterance-finally or followed by
-- a non-letter character such as space, comma, period, hyphen, etc.
text = rsub(text, "$", "")
text = rsub(text, "()", "%1")
text = rsub(text, "'+", { = 'ʺ' }) -- neutral apostrophe
text = rsub(text, '.', regular_tt)
text = rsub(text, '.', obsolete_tt)
return text
end
function export.reverse_tr(text)--reverse-translit any words or phrases
local reverse_tt = {}
for k, v in pairs(regular_tt) do
reverse_tt = k
end
reverse_tt = "'"
reverse_tt = "ь"
reverse_tt = "и"
reverse_tt = "И"
text = rsub(text, '.', acute_decomposer)
text = rsub(text, '', reverse_tt)
text = rsub(text, 'č', reverse_tt)
text = rsub(text, '.', reverse_tt)
return text
end
return export