WoW addon – Russian Translit

June 2, 2008

         During my playing in World of Warcraft, many times I have to communicate with Russian speaking players (especially now, when I in Russian guild). For me, typing Russian is a challenge: as for one who was grown in Israel, typing speed in Russian is about a word per minute. This is when I got an idea: translit addon. First of all, what translit is about: translit is solution for people like me, with have no ability to type Russian (sometimes the reason could be no Russian keyboard installed on the computer). Translit is a mapping of English letters to Russian – people typing Russian words using English letters. For example, “Zdravstvuy Mir” – “Здравствуй Мир” means in Russian “Hello World”. The idea is when a user pressing English “Z”, Russian “З” is actually being typed.
      How to use it: after installing addin, you will have new added dialog with two buttons: “eng” and “rus”. First means translit off, second means translit on. Also in key bindings menu, under “Russian Translit” header you can bind some key to activate / deactivate translit. As a mapping rules, I used well known combinations with are used in online Russian translit – www.translit.ru
      Implementation: the basic idea – somehow I have to intercept “OnKeyDown” event from chat edit box, and replace it by Russian letter, according to mapping rules. I accomplish this by hooking my script to the chat edit box:

local frame = getglobal(“ChatFrameEditBox”); //get pointer to chat edit box
frame:SetScript(“OnChar”, onTextChanged); //hook my script

      Now, for some reason the “OnKeyDown” event is not being fired, and Blizzard still have me an answer for that. So I used “OnChar” event, which means “OnKeyUp”. Obviously, my algorithm have to take in account this when performing string calculations: when the event is fired, the pressed character already located inside the string. This means first I have to delete it, and then add on it place mapped Russian character. And this means, I have to track letter position inside of the message string.

   In addition, sometimes combination of English letters means one single Russian letter. For example, “sh” means Russian “ш”. As a result, on each receiving letter I have to check previous one for possible combinations. So my algorithm going to be as the following:
1. Create new string
2. Copy all chars until current one (or until one before current one).
3. Add Russian letter with is representing pressed English key.
4. Copy all chars after current char (user could edit text in the middle of the exist string).

     So far all sounds easy. Now this starts to be more complicated: as I discovered, Russian letters advancing cursor position by 2 (!!!), while English letters and numbers by 1. This is bad (and unexpected as well), because this way I have no idea how many chars I have to copy before current one (step 2). It seems this is how WoW encoding its strings: every non English letter combined from two letters (one of them is invisible) – the code of the letter and some kind of marker, which has code 209 or 208. The workaround I doing: I checking letter before current. If it has code 208 or 209 (greater than 200) – then it means I have Russian letter there, and I have to step one more position left to take it (again, Russian letter combined from two characters):

if(strbyte(charBefore) > 200) then
charBefore = strsub(currentText, cursorPosition-2, cursorPosition-1); //take 2 chars
else
charBefore = strsub(currentText, cursorPosition-1, cursorPosition-1); //take 1 char
end

That was the trickiest part of the addon, which took me a while to understand, due to lack of documentation.

   One more interesting point: when I creating letter from combination (something like “sh”) – I have to delete two English chars, and replace it by single Russian. I achieving this by storing position offset: if single English char, then the offset is 1 (copy all characters until one position before current) or else offset is 3 (additional 2 characters representing single Russian letter).

result = strsub(currentText, 0, cursorPosition – offset); //copy all but 1 or 2 characters before current

result = result .. newChar; //add mapped russian character

if (cursorPosition < textLength) then //if we are not in the end of string, copy all rest of the letters.
result = result .. strsub(currentText, cursorPosition + 1);
end

    Key Bindings: probably I would like to activate / deactivate translit by pressing some key from keyboard, not only by clicking on the proper button using mouse. For this purpose I created Bindings.xml file. It contains pretty straightforward xml:

<Binding name=”TRANSONOFF” header = “RUSTRANS”>

      SwitchLang();

 </Binding>

Inside frame.lua, I defined meanings for name and header:

BINDING_HEADER_RUSTRANS = “Russian Translit”;
BINDING_NAME_TRANSONOFF = “Translit On/Off”;

   Now, if you will go to key bindings menu inside the game, you will find under “Russian Translit” section key bindings for “Translit On/Off” option. Each time this key will be pressed, ‘SwitchLang’ method will be called.

That’s all. You welcome to send me your feedback/suggestions/bugs.

Download addon from here.

Entry Filed under: Game Programming. Tags: .

16 Comments Add your own

  • 1. Translit  |  June 3, 2008 at 12:09 am

    Evgeni, thank you for this useful contribution! Surely many other fellow WoW players will thank you many time :)

    Reply
  • 2. Semion  |  July 19, 2008 at 6:37 am

    Thanks for this addon i wil try it asap .
    anyway for normal addon hosting you can open new progect on curse.com , for free ofc , instead of dowloading from laggy rapidshare .

    Reply
  • 3. Anonymous  |  August 6, 2008 at 3:54 pm

    Thanks for this addon, i think many people need this 6.08.

    Reply
  • 4. eye  |  August 21, 2008 at 4:53 pm

    Great idea of the addon! but… how to install it in WoW?

    Reply
  • 5. Aizikovich Evgeni  |  August 22, 2008 at 6:15 am

    Installing of the addon is very simple: just copy the addon folder as is to the YourWoWFolder\\Interface\AddOns.

    Reply
  • 6. Aizikovich Evgeni  |  August 22, 2008 at 6:20 am

    Semion – I tried to put it on the curse.com, but after I created account there I discovered I “don’t have permission to upload addon”… The curse.com administration ignored my questions regarding this issue, so… use rapidshare meanwhile )

    Reply
  • 7. eye  |  August 25, 2008 at 1:45 pm

    Yes, it’s working! Now I am able to chat with players finally :) Before I was disabled in chat because I do not know russian keyboard layout.
    Another question to author: is it possible to move that interface block up? I just have additional panel above the default one and it covers yours..
    Thank You.

    Reply
  • 8. Aizikovich Evgeni  |  August 25, 2008 at 3:24 pm

    Probably making frame being moveable is very simple – but I don’t know how :-( I tried couple things, but for some reason it doesn’t works, and I don’t have too much time to spend on this. I will be very thankful, if someone will point me how to do that. The workaround you can do, is to place addon frame in other location (maybe different corner). You doing this by editing frame location inside Frame.xml file. For example, to place frame in the right bottom corner, you can do something like this: as “Anchor point” set “BOTTOMRIGHT”, and play with offsets, for example: x=”0″ y=”50″ .

    Reply
  • 9. Nemo  |  September 30, 2008 at 1:38 pm

    What a great addon! Me and couple of my european friends joined russian guild that is on russian realm. We were chating simply typing in latin letters while other russian guys chated in cyrilic. We know russian language well but don’t know cyrilic alphabet layout on keyboard. So now we can chat in theyr language with all the respect. Thank you very mutch Evgeni

    Reply
  • 10. Anonymous  |  January 31, 2009 at 1:05 pm

    About using multiple bytes for a single char. Strings in WoW (don´t know about lua) seem to be UTF-8 encoded just as the source code. A character shown, may need 1 to 4 bytes in the string. From the unicode standard you the get the following information. Thus, if you find \224 in your string, itself and the next two bytes represent a single character.
    – UTF-8 from Unicode standard 5.0 Table 3-7
    – 00..7F 0..127 the byte itself
    – C2..DF 194..223 two byte sequence
    – E0..EF 224..239 three byte sequence
    – F0..F4 240..244 four byte sequence
    The following code replaces these byte sequences with a single ‘?’ giving a better length experience:

    return string.gsub(string.gsub(string.gsub(string.gsub(text
    , “[\240-\244]…”,”?”)
    , “[\224-\239]..”,”?”)
    , “[\192-\223].”,”?”)
    , “||”,”|”)

    Reply
  • 11. Ormek  |  January 31, 2009 at 1:05 pm

    About using multiple bytes for a single char. Strings in WoW (don´t know about lua) seem to be UTF-8 encoded just as the source code. A character shown, may need 1 to 4 bytes in the string. From the unicode standard you the get the following information. Thus, if you find \224 in your string, itself and the next two bytes represent a single character.
    – UTF-8 from Unicode standard 5.0 Table 3-7
    – 00..7F 0..127 the byte itself
    – C2..DF 194..223 two byte sequence
    – E0..EF 224..239 three byte sequence
    – F0..F4 240..244 four byte sequence
    The following code replaces these byte sequences with a single ‘?’ giving a better length experience:

    return string.gsub(string.gsub(string.gsub(string.gsub(text
    , “[\240-\244]…”,”?”)
    , “[\224-\239]..”,”?”)
    , “[\192-\223].”,”?”)
    , “||”,”|”)

    Reply
  • 12. Steven  |  February 8, 2009 at 5:23 am

    One Major problem: there is NO “Я” Key!, that is one of the most important letters since it means I in russian O_o and its used in alot of words too. Also i see no “Ю” Key…
    Example of a song that uses both keys:
    Назови мне своё имя, Я хочу узнать тебя сново! Всё по-кругу но всё будет иначе. Я даю тебе слово.

    Reply
    • 13. Aizikovich Evgeni  |  February 8, 2009 at 5:03 pm

      Hi Steven,
      As I explained in my article, some of the single russian chars composed of two english ones. The combinations is the same as at ‘http://www.translit.ru/’ site. For example: Я даю тебе слово = Ja dayu tebe slovo

      Reply
  • 14. Nathan  |  May 11, 2009 at 8:03 pm

    I think this page: http://www.wowwiki.com/UIHANDLER_OnKeyDown talks about why the OnKeyDown handler doesn’t fire for the ChatEdit frame.

    Reply
  • 15. Robert  |  October 19, 2009 at 10:49 am

    What to do if the addo is out of date? :( because my one is…

    Reply
    • 16. Aizikovich Evgeni  |  October 20, 2009 at 8:23 am

      Hi, thank you for using my addon :-)
      Yes, the addon is out of date, however as far as I know the WOW’s chatting API does not changed , so you can just mark “load out dated addons” (or something like this, don’t remember exactly) and it will work – it works fine for me.

      Reply

Leave a Comment

hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Categories

Top Posts

Tags

.NET addin app.config ArrayList bug CAB Configuration ConfigurationManager ConfigurationSection ContentControl ContextMenu CTime; DateTime custom keys DataBinding DataContext Data templates debugging equals gethashcode GUI Hashtable interlocked Invoke lock lock free memcpy MFC multithreading multithreading; lock free override performance SCSF serialization Smart Client Software Factory Styles System.Configuration unsafe virtual functions Visual Studio wait free WinAPI WinForms WinForms\WPF Integration World of Warcraft World of Warcraft; Addon

Archives