rtransliteration

Cyrillic transliteration in R


Are there packages for Cyrillic text transliteration to Latin in R? I need to convert data frames to Latin to use factors. It is somewhat messy to use Cyrillic factors in R.


Solution

  • I have found the package at last.

    > library(stringi)
    > stri_trans_general("женщина", "cyrillic-latin")
    [1] "ženŝina"
    
    > stri_trans_general("женщина", "russian-latin/bgn")
    [1] "zhenshchina"
    

    After that, the only issue remaining is the "ё" letter.

    > stri_trans_general("Ёж", "russian-latin/bgn")
    [1] "Yëzh"
    
    > stri_trans_general("подъезд", "russian-latin/bgn")
    [1] "podʺyezd"
    
    > stri_trans_general("мальчик", "russian-latin/bgn")
    [1] "malʹchik"
    

    I had to remove all the "ё", "ʹ" and "ʺ" characters

    > iconv(stri_trans_general("ёж", "russian-latin/bgn"),from="UTF8",to="ASCII",sub="")
    [1] "yzh"
    

    Or one can just remove the 'Ё' and 'ё' letters before

    > gsub('ё','e',gsub('Ё','E','Ёжики на ёлке'))
    [1] "Eжики на eлке"
    

    or after transliteration.