Simutrans-Squirrel-API
|
Let us inspect another scenario script file. We will have a look into the pak64 Pharmacy-max scenario. The objective is to get the pharmacy selling as much medicine as possible.
We will learn how to make the translation of the script's output possible.
We do not care about the meta information, and jump right into the get_rule_text method. This function does not return a plain string, it sends the string into an instance of ttext. When the simutrans program now fetches the text, it will magically translate it. This magic works only if there are translation files present.These files must be placed in a directory with the same name as the scenario, in our case at pharmacy-max/
The translation files itself are plain text files with the naming convention iso.tab
, where iso refers to the ISO abbreviation of the language (en, de, cz etc).
These text files have a simple line-oriented structure. Lets look into de.tab
:
The first line is the string as it appears in the script, it will be mapped to the string in the following line. A German user thus will read 'Alles ist erlaubt. Der Himmel (und das Bankkonto) ist die Grenze.'.
Similarly, the methods get_info_text and get_goal_text are implemented. Some interesting stuff however happens in get_result_text :
Do you see the strange{med}
string in the text? Here, you can see variable substitution in action: {med}
.
When this text is transferred to simutrans (or when text.to_string()
is called) the following happens:
{med}
as well.{med}
are replaced by the concrete number. The user will then hear 'The pharmacy sold 11 units of medicine per month.'.Now a second string is created, which features some html-like tags.
That's it. The remaining parts of this script are plain routine.