Transliteration of Russian text for sending messages to Telegram from Mikrotik RouterOS

I recently wrote a function-converter for sending messages in Russian to Telegram from Mikrotik RouterOS, which I reported here .



Now the work has been supplemented by the creation of a transliteration function that converts a string of Russian text into transliteration of the Latin alphabet. Moreover, if the string contains Latin characters, then they are not translated, that is, the function can be passed a mixed string of characters and words as an argument.



The characters are converted according to GOST 7.79-2000 (system B) . The special rules for transliterating names are not taken into account, with the exception of a special conversion of the endings "LE" is traslithered as "IE" and "OY" as "IJ".



Below is the complete function code:



# Function Translite of Russian characters for sending in Telegram
# by Sertik 16/09/2020
# usage [$FuncTransliteToTele " String .,!+"]
:global FuncTransliteToTele do={

:global string; :set $string $1;

#  table of the codes of Russian letters Translite
:local rsimv [:toarray {""="A"; ""="B"; ""="V"; ""="G"; ""="D"; ""="E"; ""="ZH"; ""="Z"; ""="I"; ""="J"; ""="K"; ""="L"; ""="M"; ""="N"; ""="O"; ""="P"; ""="R"; ""="S"; ""="T"; ""="U"; ""="F"; ""="KH"; ""="C"; ""="CH"; ""="SH"; ""="SCH"; ""="``"; ""="Y`"; ""="`"; ""="E`"; ""="JU"; ""="YA"; ""="a"; ""="b"; ""="v"; ""="g"; ""="d"; ""="e"; ""="zh"; ""="z"; ""="i"; ""="j"; ""="k"; ""="l"; ""="m"; ""="n"; ""="o"; ""="p"; ""="r"; ""="s"; ""="t"; ""="u"; ""="f"; ""="kh"; ""="c"; ""="ch"; ""="sh"; ""="sch"; ""="``"; ""="y`"; ""="`"; ""="e`"; ""="ju"; ""="ya"; ""="Yo"; ""="yo"; "№"="#"}]

# encoding of the symbols and ssembly line
:local StrTele ""; :local code "";
:for i from=0 to=([:len $string]-1) do={:local keys [:pick $string $i (1+$i)];

:local key ($rsimv->$keys); if ([:len $key]!=0) do={:set $code ($rsimv->$keys);} else={:set $code $keys};
:if (($keys="")  and ([:pick $string ($i+1) (2+$i)]="")) do={:set $code "I"; :set $i ($i+1)}
:if (($keys="")  and ([:pick $string ($i+1) (2+$i)]="")) do={:set $code "i"; :set $i ($i+1)}
:if (($keys="")  and ([:pick $string ($i+1) (2+$i)]="")) do={:set $code "I"; :set $i ($i+1)}
:if (($keys="")  and ([:pick $string ($i+1) (2+$i)]="")) do={:set $code "i"; :set $i ($i+1)}
:if (($keys="")  and ([:pick $string ($i+1) (2+$i)]="")) do={:set $code "I"; :set $i ($i+1)}
:if (($keys="")  and ([:pick $string ($i+1) (2+$i)]="")) do={:set $code "i"; :set $i ($i+1)}
:if (($keys="")  and ([:pick $string ($i+1) (2+$i)]="")) do={:set $code "i"; :set $i ($i+1)}
:if (($keys="")  and ([:pick $string ($i+1) (2+$i)]="")) do={:set $code "I"; :set $i ($i+1)}
 :set $StrTele ("$StrTele"."$code")}

:set $string $StrTele
:return $string;
}


Here's an example of how it works:



:local string [$FuncTransliteToTele "   !  - Russian alfabit  Telegramm.  "]
:log warning $string






Log output: Privet ot Mikrotik! Rabotaet funksiya-konverter Russian-alfabit dliya Telegramm. Zayac beliy.



The user can correct the transliteration table for the standard used by him. I hope it will be useful to someone. Now you can be calm about sending Russian messages to Telegram both by converting to UTF-8 codes using my converter function from here and by transliteration.



All Articles