This module will transliterate Belarusian language text per WT:BE 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:be-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 AC = require("Module:string/char")(0x0301) -- acute = ́
local rsubn = mw.ustring.gsub
local rfind = mw.ustring.find
-- 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 tt = {
='A', ='a', ='B', ='b', ='V', ='v', ='H', ='h', ='D', ='d',
='Je', ='je', ='Jo', ='jo', ='Ž', ='ž', ='Z', ='z', ='I', ='i',
='I', ='i', -- present for Old Belarusian; FIXME, remove when we have a separate language code for this lang
='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',
='Č', ='č', ='Š', ='š', ='Y', ='y', ='ʹ', ='ʹ', ='E', ='e',
='Ju', ='ju', ='Ja', ='ja',
='ʺ', ='ʺ',
-- currently non-standard, used in some older norms
='G', ='g',
-- Belarusian style quotes
='“', ='”',
};
local unstressed_vowels = "aeiyuAEIYU"
local unstressed_vowel = ""
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)
if not rfind(text, "") and rfind(text, "") then
return nil
end
text = rsub(text, "'+", { = 'ʺ' }) -- neutral apostrophe
text = rsub(text, '.', tt)
-- Mark word boundaries
text = rsub(text, "(%s+)", "#%1#")
text = "#" .. text .. "#"
-- Mark stress on <o>
text = rsub(text, "(#*)()(*" .. unstressed_vowel .. "*#)", "%1%2" .. AC .. "%3")
text = rsub(text, "(#*" .. unstressed_vowel .. "*)()(*#)", "%1%2" .. AC .. "%3")
--Strip hashes
text = rsub(text, "#", "")
return text
end
function export.reverse_tr(text)--reverse-translit any words or phrases
local reverse_tt = {}
for k, v in pairs(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)
return text
end
return export