Language code in page name (User:Ssvb/be
) not recognized.
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")
-- Highlight unstressed words with two or more syllables
local unstressed_letters = ""
for _, v in pairs(tt) do
if v ~= '“' and v ~= '”' then
unstressed_letters = unstressed_letters .. v
end
end
text = rsub(text, "#*" .. unstressed_vowel ..
"*" .. unstressed_vowel ..
"*#",
"#<span style='background-color:pink;'>%1</span>#")
--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