Hello, this is an article explaining how to make a (fairly) simple application which can translate between different languages. It includes a section on how to make a program which makes definitions files, and a section on how to make an application which can translate passages of text, using these definitions files. At the moment, this is entirely theoretical, meaning I have not actually tested that it works in multimedia fusion. But, judging on how my brain generally works as a portable MMF, it should work. :P
Making a definitions file
Array and app Structure First, an array needs to be set up, with the basic structure shown in this picture:
To make an array lie this, create an array object, set its X max dimension to 3, its Y max dimension to as high as you can, and its Z dimension to 1. Make it have a 0-based index, so make sure that the 1-based index box is unchecked. Now, make a simple program, where there are 2 edit boxes (one for the English word and one for the Translation), a button which will add it to the file, a button to load an array, a button to save an array, a button to make a new array, an edit box to input the name for the current language to be saved as the filename, and the array object. *Phew* that’s a lot of crap…
Array sorting When the user clicks the ‘new’ button, all the edit boxes should be cleared (set text to “”), and the array should be cleared. When the user clicks on the ‘load’ button, the filename written in the ‘language name’ box is loaded from the same folder as where this application is. This is doen by telling the array object to open the file: appdrive$ + appdir$ + edittext$(“language name”) +”.lng” - where “.lng” is the extension of the file. It can be whatever you want. When the user clicks the ‘save’ button, the filename in the ‘language name’ box is saved into the same folder by the array object. This is done the same way as loading it, but you use the ‘save array’ action, instead of ‘load array’.
Writing Definitions Now, onto adding words to translate. When the user presses the ‘add to definitions’ button, and the English and translated word boxes are both not empty (go to ‘compare two general conditions’ – Condition 1: Edittext$(“English word”) Condition 2: “” Then, set the middle part to ‘different’), you need to set three things inside the array: 1. The number of translations has to go up by one. This can be done by setting the value of the array at position (X=2, Y=0) to its own value + 1. 2. The English word: Set the text of the English word box to a string in the array at position (X=0, Y=value of the array at (X=2, Y=0)). 3. The Translated word: Set the text of the Translated word box to a string in the array at position (X=1, Y=value of the array at (X=2, Y=0)).
Now that’s done, you should have a small program that can create, load, and save arrays as translator definition files, and save translations for millions of different words. Now onto the actual translation program…
Making the translator
Application preparation Wow, that rhymes! *eghm* First, you need the following objects ready in your application: Two edit boxes (for the entry of text, and the translation), a combo box (language selection), two buttons (Translate TO and FROM language), the String Parser 2 Object, and the Array object. The array object will need to be set to all of the same settings as it was in the definitions file application. Once you have these objects, set them out in a good way, so that you can type large amounts of text into the two edit boxes, and all the buttons and things are obvious, and easy to use. Now, for some magical action!
Random Action At the start of the level, the combo box needs to load a list of the language files that are in the folder. To do this, tell the combo box to load a file list. When it asks you where, put in appdrive$ + appdir$ + “*.lng” – this will bring up all the language files in the same folder as the app. Also at the start of the level, make an action that sets the text of the text entry box to “enter stuff to translate here” or similar, and in the translation box, tell it to set the text as “translation will be here”.
Starting Translation This is surprisingly easy. When the user clicks on the ‘translate TO’ button, first, make the array object load the file appdrive$ + appdir$ + text(“current language”) – where “current language” is the combo box which contains the list of available languages. Then, start a fastloop called ‘transTO’, or just use loop number 0, if you’re not using the MMF built-in fastloops. Do the same for the ‘translate FROM’ button, but call the loop ‘transFROM’ instead, or use loop number 1. Now, for the loop’s actions…
Translation Loops
Translation TO the language Now, on the ‘transTO’ loop, you need to test if it is the first loop. You do this by making an event like this:
You can make the loopindex() condition by going to compare two general conditions, and choosing it from under the miscellaneous object, then going to fastloops. 0 means the first loop, so this event will only work when the loop starts, and then a different event will need to be checked to perform the actions. The actions for this event will need to be: String Parser 2 – Set source string to Edittext(“text entry”) “Translation” edit box – Set text to replace$(“string parser 2”,,)
REFERENCE POINT In place of , you will need to retrieve a string from the array at position (X=0, Y=loopindex(“transTO”)). This will retrieve the ‘English word’ string from the array, at the position relative to what the current number of the loop is. This will make it get the first string on the first loop, the second string on the second loop, etc. In place of , you will need to do the same as before, get a string from the array, but instead of using ‘X=0’, you need to use ‘X=1’. This whole event will make string parser replace the English word with the translated word… which means… translating it… yeah… *eghm* After you’ve done this loop, you need to make another event, which is almost as same as the first, but works for every fastloop afterwards. Here is what the event should be:
The only difference is that there is a greater than symbol instead of an equals sign. In the actions, only one of them is different. Instead of using: String Parser 2 – Set source string to Edittext(“text entry”) You need to use: String Parser 2 – Set source string to Edittext(“translation”) This makes it so that when it’s on a loop after the first, it already has the text in the translation box, so it needs to translate more strings in the same thing. If you used the first one, then it would keep translating the source, and in the end, you would only have one word that would have been translated. For the other actions (the replace$() things), you can just copy the stuff from the other event, or look at the explanation at REFERENCE POINT, and it’ll work the same.
Translation FROM the language For the “transFROM” loop, it is almost exactly the same as the “transTO” loop, except for what string parser 2 does in the replace$ action. Here are the events and actions needed, for the event on the first loop (with less explanation this time ;) ):
-On loop “transFROM” +loopindex(“transFROM”) = 0 ? String Parser 2 – Set source string to Edittext(“text entry”) ?“Translation” edit box – Set text to replace$(“string parser 2”,,)
In this event, what has changed is the loop name, and in the replace$ part, and have switched places. This makes it translate from language 2 to 1, instead of from language 1 to 2. To find out what and should be, go to the REFERENCE POINT, it is explained there. For the next event, that runs on every loop but the first:
-On loop “transFROM” +loopindex(“transFROM”) > 0 ? String Parser 2 – Set source string to Edittext(“translation”) ?“Translation” edit box – Set text to replace$(“string parser 2”,,)
Again, all that’s changed in this part is, as before, the text box you’re changing the text of (“translation” this time), and checking that the loop number is higher than 0.
Summary
After you’ve done all that, you should have a translator system that can translate any language that you can be bothered to input a whole bunch‘a words for. Unfortunately, it won’t be able to account for foreign language word order… but that’s not THAT important, if you just want to translate some general words some foreigners are typing, I guess. This isn’t only useful for language translation. You could use it for some general encryption purposes, if you just use single-character strings to change between, which would be fairly easy (if you remember which ones you’ve already used, and not use them twice). This could also be used to translate 1337 speak, and is a much better way of doing it than the other way I used before. Speaking of random cheese, do you have my batteries? I want them back.
Anyway, that’s all I can think of writing about (I’ve been writing this stuff for like two days, and now my ears burn), so… that’s all. Thanks for listening. Or… reading.