Modul:ru-translit

Vun Wiktionary

This module will transliterate Russian text per WT:RU TR through the function tr.

Call it so:

 {{#invoke:ru-translit|tr|ру́сский язы́к}}

-- This is a module to transliterate Russian Cyrillic words to Latin,
-- as described in [[Wiktionary:Russian transliteration]].
-- For example, in another module you can write
-- require('Module:ru-translit').tr('сло́во'), and in a template you can
-- write {{#invoke:ru-translit|tr|сло́во}}; either one becomes 'slóvo'.
 
local export = {}
 
-- Transliterates word, which should be a single word or phrase. It should
-- include stress marks, which are then preserved in the transliteration.
function export.tr(word)
    if type(word) == 'table' then -- called directly from a template
        word = word.args[1]
    end
 
    -- Ё needs converting if is decomposed
    word = word:gsub("ё","ё"):gsub("Ё","Ё")
 
    -- ё after a "hushing" consonant becomes ó (ё is mostly stressed)
    word = mw.ustring.gsub(word, "([жшчщЖШЧЩ])ё","%1ó")
    -- ю after ж and ш becomes u (e.g. брошюра, жюри)
    word = mw.ustring.gsub(word, "([жшЖШ])ю","%1u")
 
    -- е after a vowel or at the beginning of a word becomes je
    word = mw.ustring.gsub(word, "([АОУҮЫЕЯЁЮИЕЪЬаоуүыэяёюиеъь%A][́̀]?)е","%1je")
    word = mw.ustring.gsub(word, "^Е","Je")
    word = mw.ustring.gsub(word, "^е","je")
    word = mw.ustring.gsub(word, "([^Ѐ-ӿ])Е","%1Je")
    word = mw.ustring.gsub(word, "([^Ѐ-ӿ])е","%1je")
 
    return (mw.ustring.gsub(word,'.',tab))
end
 
--for adjectives and pronouns
function export.tr_adj(word)
    if type(word) == 'table' then -- called directly from a template
        word = word.args[1]
    end
 
    -- Ё needs converting if is decomposed
    word = word:gsub("ё","ё"):gsub("Ё","Ё")
 
    -- ё after a "hushing" consonant becomes ó (ё is mostly stressed)
    word = mw.ustring.gsub(word, "([жшчщЖШЧЩ])ё","%1ó")
 
    -- е after a vowel or at the beginning of a word becomes je
    word = mw.ustring.gsub(word, "([АОУЫЕЯЁЮИЕЪЬаоуыэяёюиеъь%A][́̀]?)е","%1je")
    word = mw.ustring.gsub(word, "^Е","Je")
    word = mw.ustring.gsub(word, "^е","je")
    word = mw.ustring.gsub(word, "([^Ѐ-ӿ])Е","%1Je")
    word = mw.ustring.gsub(word, "([^Ѐ-ӿ])е","%1je")
 
    --handle genitive/accusative endings, which are spelled -ого/-его (-ogo/-ego) but transliterated -ovo/-evo
    -- only for adjectives and pronouns, excluding words like много, ого
    word = mw.ustring.gsub(word, "([ое][́̀]?)го([́̀]?)$","%1vo%2")
    word = mw.ustring.gsub(word, "([ое][́̀]?)го([́̀]?%A)","%1vo%2")
 
    return (mw.ustring.gsub(word,'.',tab))
end
 
tab = {
    ["А"]="A", ["Б"]="B", ["В"]="V", ["Г"]="G", ["Д"]="D", ["Е"]="E", ["Ё"]="Ё", ["Ж"]="Ž", ["З"]="Z", ["И"]="I", ["Й"]="J",
    ["К"]="K", ["Л"]="L", ["М"]="M", ["Н"]="N", ["О"]="O", ["П"]="P", ["Р"]="R", ["С"]="S", ["Т"]="T", ["У"]="U", ["Ф"]="F",
    ["Х"]="Ch", ["Ц"]="C", ["Ч"]="Č", ["Ш"]="Š", ["Щ"]="Šč", ["Ъ"]="ʺ", ["Ы"]="Y", ["Ь"]="ʹ", ["Э"]="Ė", ["Ю"]="Ju", ["Я"]="Ja",
    ['а']='a', ['б']='b', ['в']='v', ['г']='g', ['д']='d', ['е']='e', ['ё']='ë', ['ж']='ž', ['з']='z', ['и']='i', ['й']='j',
    ['к']='k', ['л']='l', ['м']='m', ['н']='n', ['о']='o', ['п']='p', ['р']='r', ['с']='s', ['т']='t', ['у']='u', ['ф']='f',
    ['х']='ch', ['ц']='c', ['ч']='č', ['ш']='š', ['щ']='šč', ['ъ']='ʺ', ['ы']='y', ['ь']='ʹ', ['э']='ė', ['ю']='ju', ['я']='ja',
    -- Russian style quotes
    ['«']='“', ['»']='”',
    -- archaic, pre-1918 letters
    ['I']='I', ['і']='i', ['Ѳ']='F', ['ѳ']='f',
    ['Ѣ']='Ě', ['ѣ']='ě', ['Ѵ']='I', ['ѵ']='i',
}
 
function export.phr(frame)
    error("Deprecated function")
end
 
return export