Speaking In Tongues

Using the SLUDGE translation editor you can create translation files for your SLUDGE games. Each file is a list of strings and, where appropriate, translations. To add a translation file to your game, load up the project in the SLUDGE project manager and add the translation in exactly the same way as you'd add a normal sludge script. (Because the extension is .TRA not .SLU, the compiler will know a translation file when it sees one and handle it properly during compilation, which is why it's perfectly safe to add your translations to the same list as the scripts that make up your game.)

Now, of course, you'll want to test your different languages. Compile your game. In the same directory, create a text file with the same name as your compiled game, but with ".ini" instead of ".slg".

In this new, empty file add the following line:

LANGUAGE=0
Run the game again, and it should behave exactly as it did before the file existed (because 0 is the ID of the default language for your game - the language in which the game was originally written). Now, load up the ".ini" file again and change the 0 for the ID of one of your translations. Save the file and run your game again and you should now see your translation file in action.

In some situations, simply substituting one string for another may not be enough to translate a game into another language. You may have text saved as images, or want to provide alternative ways of building sentences for different languages. Take the following example:

objectType cow ("cow") {
}

objectType lookAt ("Look at") {
   event default {
      say (ego, "What a lovely " + clickedObject + ".");
   }
}

So, what would you translate the strings into? Well, I'd have thought something like...

cow -> la vache
Look at -> Voire
What a lovely -> C'est une beau
. -> .
Now, that's not going to work out quite right, is it? You'd end up with sentences like "C'est une beau la vache" and you'd get all manner of complaints. So, use the getLanguageID function to check which language you're using...

objectType cow ("cow") {
}

objectType lookAt ("Look at") {
   event default {
      if (getLanguageID () == 0) {
         say (ego, "What a lovely " + clickedObject + ".");
      } else {
         say (ego, "SIMPLE LOOK AT PHRASE HERE");
      }
   }
}

And, of course, add a translation for the new string...

SIMPLE LOOK AT PHRASE HERE -> Ce n'est pas tres interesant.
Of course, you can come up with more complicated ways around the problem, but chances are they'll be based on the above theory. Anyway, enough of special cases... time to let your users pick what language they want to use.

Adding A Front End Menu

The easiest way to let someone pick which language they want to use is to write them a program which lets them pick a language from a list somehow. There's an example here of a semi-professional looking game launcher program, all written in SLUDGE. If you want to create your own from scratch, the code to launch a game is as follows...

sub pickLanguage (number) {
   # Create a stack full of lines to output to file
   var linesToOutput = newStack ("LANGUAGE=" + number);

   # Er, output them to a file
   saveCustomData (linesToOutput, "Game name.ini");

   # Launch the game
   launch ("Game name.slg");

   # Close the launcher down
   quitGame ();
}

Changes For Distribution

If you're providing the SLUDGE engine, renamed, as part of your game .ZIP file (or installer, or whatever) then you'll probably want to run your game using your renamed copy of the SLUDGE engine rather than relying on the person who's just downloaded your game having SLUDGE installed on their machine. In this case, use the following function instead (only a couple of lines have changed, but it's simpler to add the whole thing again)...

sub pickLanguage (number) {
   # Create a stack full of lines to output to file
   var linesToOutput = newStack ("LANGUAGE=" + number);

   # Er, output them to a file
   saveCustomData (linesToOutput, "moredata.ini");

   # Launch the game
   launchWith ("Your renamed SLUDGE engine.exe", "moredata");

   # Close the launcher down
   quitGame ();
}

Compile your game and rename it moredata*. Compile your launcher and call it gamedata**. Stick them in the same folder as a copy of the SLUDGE engine, renamed as you see fit. Run the engine and it will automatically find and run gamedata... and when the pickLanguage function is called in gamedata, the launcher will start the game proper and close itself.

* = The name moredata can be changed to whatever you want. Just make sure you use the same name as the filename launched by your launcher!
** = You can't change this one. Sorry. If you want the program to run a default SLUDGE compiled game (or launcher), the file must be called gamedata.

Hopefully that's a tiny bit helpful for you all...