XF 2.1 Custom BBCode addon for translit

A. Fig Lee

Users have asked me for a BBCode which would translate latin alphabet into russian one.
What would be the best practices? I have a code from my previous php work, but want to integrate into xenforo.
That is my second day developing with xenforo, so I'm sure there are better way.
So far I came up with the following code:

namespace My;
//use XF\Pub\Controller\AbstractController;

class Translit //extends AbstractController
    private static $arr_liter=array("^J"=>"Й", "^Y"=>"Ы", "^Z"=>"З", "^C"=>"Ц", "^S"=>"С", "^X"=>"Х",
"^j"=>"й", "^y"=>"ы", "^z"=>"з", "^c"=>"ц", "^s"=>"с", "^x"=>"х",
"Jo"=>"Ё", "JO"=>"Ё",
"YO"=>"Ё", "Yo"=>"Ё", "Ju"=>"Ю",  "JU"=>"Ю",    "YU"=>"Ю", "Yu"=>"Ю", "JA"=>"Я", "Ja"=>"Я", "YA"=>"Я", "Ya"=>"Я",
"Zh"=>"Ж", "ZH"=>"Ж",    "Ch"=>"Ч", "CH"=>"Ч",    "SHH"=>"Щ", "SHh"=>"Щ", "Shh"=>"Щ", "Sh"=>"Ш", "SH"=>"Ш",
"Xh"=>"Щ", "XH"=>"Щ",    "##"=>"Ъ",    "shh"=>"щ",    "''"=>"Ь",     "jo"=>"ё",    "yo"=>"ё", "zh"=>"ж", "ch"=>"ч",
"sh"=>"ш",    "xh"=>"щ",    "ju"=>"ю",    "ja"=>"я",    "yu"=>"ю",    "ya"=>"я", "j"=>"й", "W"=>"Э", "A"=>"А", "w"=>"э",
"B"=>"Б",    "V"=>"В",    "G"=>"Г",    "D"=>"Д",    "E"=>"Е", "Z"=>"З",    "I"=>"И", "J"=>"Й",
"K"=>"К",    "L"=>"Л",    "M"=>"М",    "N"=>"Н",    "O"=>"О",    "P"=>"П",    "R"=>"Р",    "S"=>"С",    "T"=>"Т",
"U"=>"У",    "F"=>"Ф",    "H"=>"Х",    "X"=>"Х",     "C"=>"Ц",    "Y"=>"Ы",
"a"=>"а",    "b"=>"б",    "v"=>"в",    "g"=>"г",    "d"=>"д",    "e"=>"е",    "z"=>"з",    "i"=>"и",
"k"=>"к",    "l"=>"л",    "m"=>"м",    "n"=>"н",    "o"=>"о",    "p"=>"п",    "r"=>"р",    "s"=>"с",    "t"=>"т",
"u"=>"у",    "f"=>"ф",    "h"=>"х",    "x"=>"х",   "c"=>"ц",    "#"=>"ъ",    "y"=>"ы",    "'"=>"ь"

    private static function convert_liter_up($s_string){//latin to cyrillic
        global $arr_liter;
        foreach(self::$arr_liter as $k=>$v)
                $s_ret=str_replace($k, $v, $s_ret);
        return $s_ret;
    public static function translate($tagChildren, $tagOption, $tag, array $options,
                                     \XF\BbCode\Renderer\AbstractRenderer $renderer) {
        $output = '';
        foreach ($tagChildren AS $element)
            if (is_array($element))
                $options['stack'][] = $element;
                $output .= $renderer->renderTag($element, $options);
                $output .= self::convert_liter_up($renderer->renderString($element, $options));

        return $output;

As you may see it simple copy/paste from Traverser::renderSubTree
I think I need I have to subclass AbstractController and simply override

But I see when I click replay to such posts, I see original
code with wrapping BBCode, like
instead of

Meanwhile, original BBCodes B, I etc works perfectly and seem they are implemented differently through filter.
So, 2 questions:
1. Is it design wise correct to subclass AbstractController and override renderString?
2. Am I going right direction or should I concentrate on filter interface and look how BBCode B, I is implemented
Top Bottom