Mòdul:Ru-trans Documentació del mòdul [ mostra ] [ modifica el codi ] [ mostra l'historial ] [ refresca ]
A continuació es mostra la documentació transclosa de la subpàgina /ús. [salta a la caixa de codi] Transcripció del rus al català segons els criteris de Viquipèdia:Transcripció del rus. Actualment s'usa només com a eina de consulta, vegeu Viquipèdia:Transcripció del rus#Consulta. El codi original prové de wikt:Mòdul:ru-trans on s'utilitza per generar transcripcions automàtiques. En cas de modificacions és convenient mantenir-lo sincronitzat amb l'original. local p = {}
local u = mw.ustring.char
local GR = u(0x0300) -- grave = ̀
local AC = u(0x0301) -- acute = ˊ
local DI = u(0x0308) -- diaeresis = ¨
local tab = {
["А"]="A", ["Б"]="B", ["В"]="V", ["Г"]="G", ["Д"]="D", ["Е"]="E", ["Ё"]="Io", ["Ж"]="J", ["З"]="Z", ["И"]="I", ["Й"]="I",
["К"]="K", ["Л"]="L", ["М"]="M", ["Н"]="N", ["О"]="O", ["П"]="P", ["Р"]="R", ["С"]="S", ["Т"]="T", ["У"]="U", ["Ф"]="F",
["Х"]="Kh", ["Ц"]="Ts", ["Ч"]="Tx", ["Ш"]="X", ["Щ"]="Sx", ["Ъ"]="", ["Ы"]="I", ["Ь"]="", ["Э"]="E", ["Ю"]="Iu", ["Я"]="Ia",
['а']='a', ['б']='b', ['в']='v', ['г']='g', ['д']='d', ['е']='e', ['ё']='io', ['ж']='j', ['з']='z', ['и']='i', ['й']='i',
['к']='k', ['л']='l', ['м']='m', ['н']='n', ['о']='o', ['п']='p', ['р']='r', ['с']='s', ['т']='t', ['у']='u', ['ф']='f',
['х']='kh', ['ц']='ts', ['ч']='tx', ['ш']='x', ['щ']='sx', ['ъ']='', ['ы']='i', ['ь']='', ['э']='e', ['ю']='iu', ['я']='ia',
-- archaic, pre-1918 letters
['І']='I', ['і']='i', ['Ѳ']='F', ['ѳ']='f',
['Ѣ']='E', ['ѣ']='e', ['Ѵ']='I', ['ѵ']='i',
-- composed combinations with grave accents map to uncomposed letters
-- for consistency with other char+grave combinations
['ѐ'] = 'e' .. GR, ['Ѐ'] = 'E' .. GR, ['ѝ'] = 'i' .. GR, ['Ѝ'] = 'I' .. GR
}
-- FIXME! Doesn't work with ɣ, which gets included in this character set
local non_consonants = "[АОУҮЫЭЯЁЮИЕЪЬІѢѴаоуүыэяёюиеъьіѣѵAEIOUYƐaeiouyɛʹʺ%A]"
local function map_to_je(pre, e)
local map_to_je_map = {["Е"] = "Ie", ["е"] = "ie", ["Ѣ"] = "Ie", ["ѣ"] = "ie"}
if e == nil then
return map_to_je_map[pre]
end
return pre .. map_to_je_map[e]
end
local function ureverse(s) -- equivalent a string.reverse, no existeix mw.ustring.reverse
local ret = ""
for i = 1, mw.ustring.len(s) do
ret = mw.ustring.sub(s, i, i) .. ret
end
return ret
end
-- Transliterates a single word. It should include stress marks, which are then preserved in the transliteration.
local function wtr(cyr)
cyr = mw.ustring.gsub(cyr, GR, AC)
-- reducció de consonants duplicades no usades en català
local no_dobles = {"([Вв])в", "([Жж])ж", "([Кк])к", "([Хх])х", "([Цц])ц", "([Чч])ч", "([Шш])ш", "([Щщ])щ"}
for i = 1, #no_dobles do
cyr = mw.ustring.gsub(cyr, no_dobles[i], "%1")
end
-- si no hi ha cap accent i alguna ё, accentuem la darrera
if mw.ustring.find(cyr, '[Ёё]') then
if not mw.ustring.find(cyr, AC) then
cyr = ureverse(mw.ustring.gsub(ureverse(cyr), "([Ёё])", AC .. "%1", 1))
end
end
-- ё after a "hushing" consonant becomes o
cyr = mw.ustring.gsub(cyr, "([жшчщЖШЧЩ])ё","%1o")
-- е after a vowel or at the beginning of a word becomes ie
cyr = mw.ustring.gsub(cyr, "^([ЕеѢѣ])", map_to_je)
cyr = mw.ustring.gsub(cyr, "(" .. non_consonants .. ")([ЕеѢѣ])", map_to_je)
-- need to do it twice in case of sequences of such vowels
cyr = mw.ustring.gsub(cyr, "(" .. non_consonants .. ")([ЕеѢѣ])", map_to_je)
local latin = mw.ustring.gsub(cyr, '.', tab)
-- simplificació de dues i
latin = mw.ustring.gsub(latin, "(i" .. AC .. "?)i", "%1")
-- doble ela a ela geminada
latin = mw.ustring.gsub(latin, "([Ll])([Ll])", "%1·%2")
-- correcció gue/gui
latin = mw.ustring.gsub(latin, "([Gg])([ei])", "%1u%2")
-- regles d'accentuació en català
local char_acc = {["A"..AC]="À", ["E"..AC]="É", ["I"..AC]="Í", ["O"..AC]="Ó", ["U"..AC]="Ú",
["a"..AC]="à", ["e"..AC]="é", ["i"..AC]="í", ["i"..DI]="ï", ["o"..AC]="ó", ["u"..AC]="ú", ["u"..DI]="ü"}
latin = require("Mòdul:ca-trans").accents(latin)
-- accent obert à
latin = mw.ustring.gsub(latin, ".[" .. AC .. DI .. "]", char_acc)
-- correcció intervocàlica ss, ix
latin = mw.ustring.gsub(latin, "([AEIOUaeiouÀÉÍÓÚàéíóúü])s([aeiouàéíóú])", "%1ss%2")
latin = mw.ustring.gsub(latin, "([AEOUaeouÀÉÓÚàéóúü])x", "%1ix")
return latin
end
-- Transliterates text, a single word or phrase.
function p.tr(text)
if type(text) == "table" then text = text.args[1] end
local trwords = {}
for word in mw.text.gsplit(text, '%s') do
table.insert(trwords, wtr(word))
end
return table.concat(trwords, ' ')
end
return p
|