-- Denna modul används för att transkribera ukrainska.
--
-- För att transkribera bulgariska, ryska och vitryska/belarusiska kan
-- ett liknande system användas. Det hanteras dock av särskilda moduler. Se:
--
-- Modul:translit/be
-- Modul:translit/bg
-- Modul:translit/ru
--
-- Systemet för translitterering följer det som anges i
-- "Svenska skrivregler" (2017), fjärde upplagan, red. Ola Karlsson
-- En kopia av avsnittet finns i skrivande stund här:
-- https://www.isof.se/download/18.648bef4b18093ee2f03ee80/1652364347434/Kyrillisk%20tabell%20SS2017.pdf
--
-- Denna modul används av följande mall:
-- {{tr}}
--
-- Modulen är författad av (och underhålls av) [[Användare:Gabbe]]
local export = {}
local Q = require("Modul:queue")
local multibyte_char_pattern = ".[\128-\191]*"
local latin_by_cyrillic = { ["А"]="A", ["а"]="a", ["Б"]="B", ["б"]="b", ["В"]="V",
["в"]="v", ["Г"]="H", ["г"]="h", ["Ґ"]="G", ["ґ"]="g", ["Д"]="D", ["д"]="d",
["Е"]="E", ["е"]="e", ["Є"]="Je", ["є"]="je", ["Ж"]="Zj", ["ж"]="zj",
["З"]="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", ["Х"]="Ch", ["х"]="ch", ["Ц"]="Ts", ["ц"]="ts",
["Ч"]="Tj", ["ч"]="tj", ["Ш"]="Sj", ["ш"]="sj", ["Щ"]="Sjtj", ["щ"]="sjtj",
["Ъ"]="", ["ъ"]="", ["Ь"]="J", ["ь"]="j", ["Э"]="E", ["э"]="e",
["Ю"]="Ju", ["ю"]="ju", ["Я"]="Ja", ["я"]="ja"
}
-- Själva transkriberingsfunktionen för ukrainska
function export.tr (text)
cyrillic_q = Q()
latin_q = Q()
for c in string.gmatch(text, multibyte_char_pattern) do
Q.enqueue(cyrillic_q, c)
end
repeat
local x = Q.dequeue(cyrillic_q)
local y = Q.peekFirst(cyrillic_q)
local z = Q.peekSecond(cyrillic_q)
local u = Q.peekLast(latin_q)
local accent = "́"
if not latin_by_cyrillic[x] then
Q.enqueue(latin_q, x)
elseif x == "ь" then
if y == "и" then
Q.enqueue(latin_q, "j")
end
elseif x == "Ь" then
if y == "и" or y == "И" then
Q.enqueue(latin_q, "J")
end
elseif mw.ustring.find(x, "[стзСТЗ]") then
Q.enqueue(latin_q,latin_by_cyrillic[x])
if y == "ь" then
if z == "ю" then
Q.enqueue(latin_q,"iu")
Q.dequeue(cyrillic_q)
Q.dequeue(cyrillic_q)
elseif z == "я" then
Q.enqueue(latin_q,"ia")
Q.dequeue(cyrillic_q)
Q.dequeue(cyrillic_q)
end
elseif y == "ю" then
Q.enqueue(latin_q,"iu")
Q.dequeue(cyrillic_q)
elseif y == "я" then
Q.enqueue(latin_q,"ia")
Q.dequeue(cyrillic_q)
end
else
Q.enqueue(latin_q, latin_by_cyrillic[x])
end
until Q.isEmpty(cyrillic_q)
local tbl = {}
repeat
local x = Q.dequeue(latin_q)
local y = Q.peekFirst(latin_q) or ""
local accent = "́"
if y == accent then
x = mw.ustring.toNFC(x .. y)
Q.dequeue(latin_q)
end
table.insert(tbl, x)
until Q.isEmpty(latin_q)
text = table.concat(tbl, "")
return text
end
return export