If your asset has a script, then you have the potential for all kinds of problems when it comes time to translate it.
You must not display text directly from the script file itself. Put all displayed text in the string table, and load it from there. Debug logging is the only exception to this rule.
Do not put anything in the String Table that is not used directly as displayed text. Localisation teams will re-write the entire contents of the string-table container. If you are looking for a location to load arbitrary configuration data, you should be using the extensions container.
You can get an object representing the string table by calling GetStringTable() on an Asset. A 'StringTable' object will be returned. This code will get the string table for the current asset:
Strings from that string table object will be in the users local language, or English if no local translation is available.
Generally you'd declare the string table as a member in your class, and initialise it within the Init() function, like this:
At any point in the code, When you need a string, you can then use:
This will look up the line "example-string-table-entry" in the string table, and return that text.
Sometimes, a single entry isn't enough. If you are making a sentence, avoid any code which makes assumptions about how the sentence is constructed - those assumptions may not be valid in other languages. In particular, concatenating strings in code is going to cause problems.
Let's look at a sentence like this:
"Pick up the (3) loaded (flat/stake/box/gondola/hopper) cars from (<Bob's Lumber>)."
... with anything in brackets capable of changing.
It is understandably tempting to write something like this:
Please don't. While this might look fine in English, and maybe in a few other western European languages, you've coded the sentence structure into the script. The moment you need to switch the order of the number, car type, or industry name within the sentence for a language, it stops working. Instead you should write something like:
The string table should look like this:
The tokens ($0, $1, and $2) in 'pickup-text' are replaced by the strings used in the parameters to the GetString3() call. You can do this with up to ten substitutions, using the functions GetString1() to GetString10().
You must not display text directly from the script file itself. Put all displayed text in the string table, and load it from there. Debug logging is the only exception to this rule.
Do not put anything in the String Table that is not used directly as displayed text. Localisation teams will re-write the entire contents of the string-table container. If you are looking for a location to load arbitrary configuration data, you should be using the extensions container.
You can get an object representing the string table by calling GetStringTable() on an Asset. A 'StringTable' object will be returned. This code will get the string table for the current asset:
Code:
StringTable textStrings = GetAsset().GetStringTable();
Strings from that string table object will be in the users local language, or English if no local translation is available.
Generally you'd declare the string table as a member in your class, and initialise it within the Init() function, like this:
Code:
class MyCustomScriptedLoco isclass Locomotive
{
StringTable m_textStrings; // string table gets loaded here
...
public void Init(void)
{
inherited();
// Load the string table
m_textStrings = GetAsset().GetStringTable();
...
}
...
};
At any point in the code, When you need a string, you can then use:
Code:
m_textStrings.GetString("example-string-table-entry");
This will look up the line "example-string-table-entry" in the string table, and return that text.
Sometimes, a single entry isn't enough. If you are making a sentence, avoid any code which makes assumptions about how the sentence is constructed - those assumptions may not be valid in other languages. In particular, concatenating strings in code is going to cause problems.
Let's look at a sentence like this:
"Pick up the (3) loaded (flat/stake/box/gondola/hopper) cars from (<Bob's Lumber>)."
... with anything in brackets capable of changing.
It is understandably tempting to write something like this:
Code:
outString = m_textStrings.GetString("pickup-part-1") + carCount + m_textStrings.GetString("pickup-part-2") + m_textStrings.GetString("car-description-" + carType) + m_textStrings.GetString("pickup-part-3") + theIndustry.GetLocalisedName();
Please don't. While this might look fine in English, and maybe in a few other western European languages, you've coded the sentence structure into the script. The moment you need to switch the order of the number, car type, or industry name within the sentence for a language, it stops working. Instead you should write something like:
Code:
outString = m_textStrings.GetString3("pickup-text", carCount, m_textStrings.GetString("car-description-" + carType), theIndustry.GetLocalisedName();
The string table should look like this:
Code:
string-table
{
pickup-text "Pick up the $0 loaded $1 cars from $2."
car-description-box "box"
car-description-flat "flat"
car-description-gondola "gondola"
car-description-hopper "hopper"
car-description-stake "stake"
}
The tokens ($0, $1, and $2) in 'pickup-text' are replaced by the strings used in the parameters to the GetString3() call. You can do this with up to ten substitutions, using the functions GetString1() to GetString10().