Tutorials
Russian Transliterator Addon

Transliterator is an abstract class that transliterates text from one format to another. Russian to Latin transliterator changes Russian text written in Cyrillic characters to phonetically equivalent Latin characters.

Only useful for Russian speaking community!

Open sites/default/assets/js/editor.js

Add on top right after:

//avoid alt+e and alt+f key combinations

This:

var CapsState = false;

function copy() {
  let textarea = document.getElementById("textarea");
  textarea.select();
  document.execCommand("copy");
}

function initArray() 
{
    this.length = initArray.arguments.length
    for (var i = 0; i < this.length; i++)   
        this[i+1] = initArray.arguments[i]
}

eng_letters = new initArray(1040,1041,1062,1044,1045,1060,1043,1061,1048,1049,1050,1051,1052,1053,1054,1055,1071,1056,1057,1058,1059,1042,1065,1061,1067,1047,91,92,93,94,95,96,1072,1073,1094,1076,1077,1092,1075,1093,1080,1081,1082,1083,1084,1085,1086,1087,1103,1088,1089,1090,1091,1074,1097,120,1099,1079);
second_order = new initArray(72,79,69,85,65,72,77,79,85,65,72,104,111,101,117,97,104,109,111,117,97,104);
first_order  = new initArray(1062,1049,1049,1049,1049,1057,1065,1067,1067,1067,1047,1094,1081,1081,1081,1081,1089,1097,1099,1099,1099,1079);
two_result = new initArray(1063,1025,1069,1070,1071,1064,1068,1025,1070,1071,1046,1095,1105,1101,1102,1103,1096,1100,1105,1102,1103,1078);

var nexto = 1;
var language = (navigator.appName=='Netscape');

function getlanguagename()
{
    if (language==1) return "Eng";
    if (language==0) return "Rus";
}

function changelanguage()
{
if (language==1) {language=0; document.translitform.rus_eng.value="Rus"; document.translitform.input_text.focus();return 0}
if (language==0) {language=1; document.translitform.rus_eng.value="Eng"; document.translitform.input_text.focus();return 0}
}

function translate_letter()
{
    if(navigator.appName=='Netscape')
    {
        if (language==0) 
        {
            changelanguage();
            alert("The language is swithched to English. Please complete the text and press 'TRANSLITERATE ALL' button");
        }
        return true;
    }
        if (language==1) {return true;}
    var txt = document.translitform.input_text.value;
    l1 = txt.substr(txt.length - 1,1);
    var code = l1.charCodeAt(0); 
    l2 = txt.substr(txt.length-2,1);
    var code2 = l2.charCodeAt(0);
    if ((code==39)||(code==35))
    //' and '' and # and ## treatment
    {
        if (code==39) 
        {
            var newcode =1100;
            var doublecode =1068;
        }
        if (code==35) 
        {
            var newcode =1098;
            var doublecode =1066;
        }

        var res = String.fromCharCode(newcode);        
        txt = txt.substr(0, txt.length-1);
        if (code2==newcode) 
        { 
            res = String.fromCharCode(doublecode);
            txt = txt.substr(0, txt.length-1);
        }

        document.translitform.input_text.value = txt + res;
                document.translitform.input_text.focus();
    }

    if ((code<123) && (code>64)) 
    {
        var res = String.fromCharCode(eng_letters[code-64]);
        var rus_code = eng_letters[code-64];
        txt = txt.substr(0, txt.length-1);
        if (nexto==0)
        { 
            nexto = 1;
            for (i = 1; i<25; i++)
            {
                if (rus_code == first_order[i]) nexto = 0; 
                if ((code==second_order[i])&&(code2==first_order[i])) 
                { 
                    res = String.fromCharCode(two_result[i]);
                    txt = txt.substr(0, txt.length-1);
                    break;
                }
            }
        }
        else nexto = 0;

                document.translitform.input_text.focus();
        document.translitform.input_text.value = txt + res;

    }
}


function translatesymbol(pretxt,txt)
{
    var res = pretxt+txt;
    var code = txt.charCodeAt(0); 
    var code2 = pretxt.charCodeAt(0);

    if ((code==39)||(code==35))
    //' and '' and # and ## treatment
    {
        if (code==39) 
        {
            var newcode =1100;
            var doublecode =1068;
        }
        if (code==35) 
        {
            var newcode =1098;
            var doublecode =1066;
        }

        res = pretxt+String.fromCharCode(newcode);        

        if (code2==newcode) 
        { 
            res = String.fromCharCode(doublecode);
        }
    }

    if ((code<123) && (code>64)) 
    {
        res = pretxt+String.fromCharCode(eng_letters[code-64]);
        for (i = 1; i<25; i++)
        { 
            if ((code==second_order[i])&&(code2==first_order[i])) 
            { 
                res = String.fromCharCode(two_result[i]);
                break;
            }
        }
    }
    return res;
}

function translateAll()
{
    var txt = document.translitform.input_text.value;
    var txtnew = translatesymbol("",txt.substr(0,1));
    var symb = "";
    for (kk=1;kk<txt.length;kk++)
    {
        symb = translatesymbol(txtnew.substr(txtnew.length-1,1),txt.substr(kk,1));
        txtnew = txtnew.substr(0,txtnew.length-1) + symb;
    }
    document.translitform.input_text.value = txtnew;
    document.translitform.input_text.focus();
}

     function onClickKBButtonEx(btn)
     {
    if (btn == 'Caps')
        CapsState = !(CapsState)
        else
    { 
        var txt = document.translitform.input_text.value;
        if (btn == 'BkSp')
        {
            txt = txt.substr(0, txt.length - 1);
        }
        else
        {
            txt = txt + btn;
        }
        document.translitform.input_text.value = txt;
    }
        document.translitform.input_text.focus();
     }
     function onClickKBButton(btn)
     {
    var code = btn.charCodeAt(0);
    if (CapsState == false)
    {
        if (code == 168) 
                   code = 184;
        else if (code == 1025)
           code = 1105;
        else
                   code = code + 32;
    }
    btn = String.fromCharCode(code);
    onClickKBButtonEx(btn);
     }

Find:

],
    previewInElement: jQuery('#codo_new_reply_preview'),

Add Before:

{name: 'Translit', className: "translit", replaceWith: translateAll},

(That is if you are using my colors and headers bbcode change)
Save and close.

open sites/default/themes/default/less/editor.less

Find:

.markItUp .preview a {
    background-image:url(../img/preview.png);
}

Add before:

.markItUp .translit {
   left: 340px;
   position: absolute;
}
.markItUp .markItUpButton13 a    {
    background-image:url(../img/translit.png);
}

Add image to sites/default/themes/default/img
5f09f48d20b38

Open sites/default/themes/default/templates/forum/new_topic.tpl
Find:

<form id="codo_new_reply_post"  method="POST" class="" role="form">

Replace with:

<form method="post" id="codo_new_reply_post" onsubmit="return false;" name="translitform" enctype="multipart/form-data" role="form">

Find:

<textarea placeholder="{_t('Describe your topic . You can use BBcode or Markdown')}" id="codo_new_reply_textarea" name="input_text">{$topic.imessage}</textarea>

Open sites/default/themes/default/templates/forum/topic.tpl

Find:

<form id="codo_new_reply_post" action="/" method="POST">

Replace with:

<form id="codo_new_reply_post" action="/" onsubmit="return false;" name="translitform" enctype="multipart/form-data" method="POST">

Find:

<textarea placeholder="{_t('Start typing here . You can use BBcode or Markdown')}" id="codo_new_reply_textarea" name="input_text"></textarea>

Replace with:

<textarea onkeyup="translate_letter()" placeholder="{_t('Start typing here . You can use BBcode or Markdown')}" id="codo_new_reply_textarea" name="input_text"></textarea>

Done!

Transliterator is an abstract class that transliterates text from one format to another. Russian to Latin transliterator changes Russian text written in Cyrillic characters to phonetically equivalent Latin characters. Only useful for Russian speaking community! Open **sites/default/assets/js/editor.js** Add on top right after: ```` //avoid alt+e and alt+f key combinations ```` This: ```` var CapsState = false; function copy() { let textarea = document.getElementById(&quot;textarea&quot;); textarea.select(); document.execCommand(&quot;copy&quot;); } function initArray() { this.length = initArray.arguments.length for (var i = 0; i &lt; this.length; i++) this[i+1] = initArray.arguments[i] } eng_letters = new initArray(1040,1041,1062,1044,1045,1060,1043,1061,1048,1049,1050,1051,1052,1053,1054,1055,1071,1056,1057,1058,1059,1042,1065,1061,1067,1047,91,92,93,94,95,96,1072,1073,1094,1076,1077,1092,1075,1093,1080,1081,1082,1083,1084,1085,1086,1087,1103,1088,1089,1090,1091,1074,1097,120,1099,1079); second_order = new initArray(72,79,69,85,65,72,77,79,85,65,72,104,111,101,117,97,104,109,111,117,97,104); first_order = new initArray(1062,1049,1049,1049,1049,1057,1065,1067,1067,1067,1047,1094,1081,1081,1081,1081,1089,1097,1099,1099,1099,1079); two_result = new initArray(1063,1025,1069,1070,1071,1064,1068,1025,1070,1071,1046,1095,1105,1101,1102,1103,1096,1100,1105,1102,1103,1078); var nexto = 1; var language = (navigator.appName==&#039;Netscape&#039;); function getlanguagename() { if (language==1) return &quot;Eng&quot;; if (language==0) return &quot;Rus&quot;; } function changelanguage() { if (language==1) {language=0; document.translitform.rus_eng.value=&quot;Rus&quot;; document.translitform.input_text.focus();return 0} if (language==0) {language=1; document.translitform.rus_eng.value=&quot;Eng&quot;; document.translitform.input_text.focus();return 0} } function translate_letter() { if(navigator.appName==&#039;Netscape&#039;) { if (language==0) { changelanguage(); alert(&quot;The language is swithched to English. Please complete the text and press &#039;TRANSLITERATE ALL&#039; button&quot;); } return true; } if (language==1) {return true;} var txt = document.translitform.input_text.value; l1 = txt.substr(txt.length - 1,1); var code = l1.charCodeAt(0); l2 = txt.substr(txt.length-2,1); var code2 = l2.charCodeAt(0); if ((code==39)||(code==35)) //&#039; and &#039;&#039; and # and ## treatment { if (code==39) { var newcode =1100; var doublecode =1068; } if (code==35) { var newcode =1098; var doublecode =1066; } var res = String.fromCharCode(newcode); txt = txt.substr(0, txt.length-1); if (code2==newcode) { res = String.fromCharCode(doublecode); txt = txt.substr(0, txt.length-1); } document.translitform.input_text.value = txt + res; document.translitform.input_text.focus(); } if ((code&lt;123) &amp;&amp; (code&gt;64)) { var res = String.fromCharCode(eng_letters[code-64]); var rus_code = eng_letters[code-64]; txt = txt.substr(0, txt.length-1); if (nexto==0) { nexto = 1; for (i = 1; i&lt;25; i++) { if (rus_code == first_order[i]) nexto = 0; if ((code==second_order[i])&amp;&amp;(code2==first_order[i])) { res = String.fromCharCode(two_result[i]); txt = txt.substr(0, txt.length-1); break; } } } else nexto = 0; document.translitform.input_text.focus(); document.translitform.input_text.value = txt + res; } } function translatesymbol(pretxt,txt) { var res = pretxt+txt; var code = txt.charCodeAt(0); var code2 = pretxt.charCodeAt(0); if ((code==39)||(code==35)) //&#039; and &#039;&#039; and # and ## treatment { if (code==39) { var newcode =1100; var doublecode =1068; } if (code==35) { var newcode =1098; var doublecode =1066; } res = pretxt+String.fromCharCode(newcode); if (code2==newcode) { res = String.fromCharCode(doublecode); } } if ((code&lt;123) &amp;&amp; (code&gt;64)) { res = pretxt+String.fromCharCode(eng_letters[code-64]); for (i = 1; i&lt;25; i++) { if ((code==second_order[i])&amp;&amp;(code2==first_order[i])) { res = String.fromCharCode(two_result[i]); break; } } } return res; } function translateAll() { var txt = document.translitform.input_text.value; var txtnew = translatesymbol(&quot;&quot;,txt.substr(0,1)); var symb = &quot;&quot;; for (kk=1;kk&lt;txt.length;kk++) { symb = translatesymbol(txtnew.substr(txtnew.length-1,1),txt.substr(kk,1)); txtnew = txtnew.substr(0,txtnew.length-1) + symb; } document.translitform.input_text.value = txtnew; document.translitform.input_text.focus(); } function onClickKBButtonEx(btn) { if (btn == &#039;Caps&#039;) CapsState = !(CapsState) else { var txt = document.translitform.input_text.value; if (btn == &#039;BkSp&#039;) { txt = txt.substr(0, txt.length - 1); } else { txt = txt + btn; } document.translitform.input_text.value = txt; } document.translitform.input_text.focus(); } function onClickKBButton(btn) { var code = btn.charCodeAt(0); if (CapsState == false) { if (code == 168) code = 184; else if (code == 1025) code = 1105; else code = code + 32; } btn = String.fromCharCode(code); onClickKBButtonEx(btn); } ```` Find: ```` ], previewInElement: jQuery(&#039;#codo_new_reply_preview&#039;), ```` Add Before: ```` {name: &#039;Translit&#039;, className: &quot;translit&quot;, replaceWith: translateAll}, ```` (That is if you are using my colors and headers bbcode change) Save and close. open **sites/default/themes/default/less/editor.less** Find: ```` .markItUp .preview a { background-image:url(../img/preview.png); } ```` Add before: ```` .markItUp .translit { left: 340px; position: absolute; } .markItUp .markItUpButton13 a { background-image:url(../img/translit.png); } ```` Add image to **sites/default/themes/default/img** ![5f09f48d20b38](serve/attachment&amp;path=5f09f48d20b38) Open **sites/default/themes/default/templates/forum/new_topic.tpl** Find: ```` &lt;form id=&quot;codo_new_reply_post&quot; method=&quot;POST&quot; class=&quot;&quot; role=&quot;form&quot;&gt; ```` Replace with: ```` &lt;form method=&quot;post&quot; id=&quot;codo_new_reply_post&quot; onsubmit=&quot;return false;&quot; name=&quot;translitform&quot; enctype=&quot;multipart/form-data&quot; role=&quot;form&quot;&gt; ```` Find: ```` &lt;textarea placeholder=&quot;{_t(&#039;Describe your topic . You can use BBcode or Markdown&#039;)}&quot; id=&quot;codo_new_reply_textarea&quot; name=&quot;input_text&quot;&gt;{$topic.imessage}&lt;/textarea&gt; ```` Open **sites/default/themes/default/templates/forum/topic.tpl** Find: ```` &lt;form id=&quot;codo_new_reply_post&quot; action=&quot;/&quot; method=&quot;POST&quot;&gt; ```` Replace with: ```` &lt;form id=&quot;codo_new_reply_post&quot; action=&quot;/&quot; onsubmit=&quot;return false;&quot; name=&quot;translitform&quot; enctype=&quot;multipart/form-data&quot; method=&quot;POST&quot;&gt; ```` Find: ```` &lt;textarea placeholder=&quot;{_t(&#039;Start typing here . You can use BBcode or Markdown&#039;)}&quot; id=&quot;codo_new_reply_textarea&quot; name=&quot;input_text&quot;&gt;&lt;/textarea&gt; ```` Replace with: ```` &lt;textarea onkeyup=&quot;translate_letter()&quot; placeholder=&quot;{_t(&#039;Start typing here . You can use BBcode or Markdown&#039;)}&quot; id=&quot;codo_new_reply_textarea&quot; name=&quot;input_text&quot;&gt;&lt;/textarea&gt; ```` Done!

My page http://russianmichigan.ml/MadRomas

edited Jul 11 at 6:23 pm

Result:

When text is written "Privet!" when Transliterator is clicked it becomes:

5f09f6977165e

Test it here: http://anyday.ml

Result: When text is written &quot;Privet!&quot; when Transliterator is clicked it becomes: ![5f09f6977165e](serve/attachment&amp;path=5f09f6977165e) Test it here: http://anyday.ml

My page http://russianmichigan.ml/MadRomas

20
1
1
live preview
enter atleast 10 characters
WARNING: You mentioned %MENTIONS%, but they cannot see this message and will not be notified
Saving...
Saved
With selected deselect posts show selected posts
All posts under this topic will be deleted ?
Pending draft ... Click to resume editing
Discard draft