Localization

Knights currently has a work-in-progress localization system. This means that, eventually, it will become possible to translate the game into different languages.

The system works by defining a set of localization "keys" which correspond to individual messages. For example, the key healing corresponds to the message "Healing" (in English). When the user drinks a healing potion, the Lua code calls kts.FlashMessage("healing"); the game then looks up healing in the file knights_data/client/localization_strings.txt, finds the corresponding message "Healing", and displays that message on-screen.

In theory, to support other languages, all we would need to do is substitute a different localization_strings.txt file. For example, in German, healing might map to "Heilung".

In practice, not all of the in-game messages have been moved over to the localization system yet, so only a partial translation would be possible right now. Also, the game doesn't provide any kind of UI for the user to select a language. Finally, the game code only partially supports Unicode (e.g. a lot of the UI can only handle Latin-1 strings at this time), so languages like Russian or Greek would be impossible to support currently. It is hoped that these issues will be resolved in the future.

Localization system features

One feature of the system is that localization messages can include parameters (numbered from zero). For example, the message for desc_escape_gems is "Your mission is to escape via {0} with {1} out of {2} gems.". Here, {0}, {1} and {2} are parameters. Parameters will be substituted at runtime with various things like other localized strings, player names, or raw numbers. For example, in this case, {0} might map to the message "your entry point" (coming from the localization key desc_exit_same), and {1} and {2} might map to the numbers 3 and 4 respectively, to make the message "Your mission is to escape via your entry point with 3 out of 4 gems.".

Another feature of the system is that messages can have separate variants for singular and plural forms. In English these two forms are called one and other, respectively (different rules might be defined for different languages, and some languages may have more than two forms). For example, the localization strings file defines both retrieve_gem[one], which maps to "Retrieve {0} gem", and retrieve_gem[other], which maps to "Retrieve {0} gems".

Finally, some messages support lists of parameters using a special ... syntax. Since this is a fairly rare special case, it is not described fully here, but see the message is_winner in localization_strings.txt for an example.

Specifying localization messages in Lua

In Lua, there are many functions which take a localized message as a parameter: e.g. kts.FlashMessage and kts.PrintLoc.

For the localization message parameter, the Lua code may pass either of the following things:

Examples:

See also

knights_data/client/localization_strings.txt, where the localization keys (and corresponding messages) are defined.

Future work