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_english.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 file. For example, in localization_german.txt, "healing" might map to "Heilung".

In practice, some areas of the game (e.g. the tutorial) haven't been added to the localization system yet, so they can't currently be translated; hopefully this can be resolved at some point.

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_english.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 localized message itself, the Lua code may pass either of the following:

Examples:

Providing new localized strings in mods

Individual Lua mods can also include localization_LANGUAGE.txt files in their root directory. The game will pick these up automatically.

Note that if a mod defines a localization key that already exists (in the base game, or from an earlier mod), then the text for that key will be overwritten. This can sometimes be useful – it allows mods to update text from the base game (or other mods) if they want – but it also carries the risk of accidental name clashes. To mitigate this, it's recommended that mods should use their mod name as a prefix when creating new localization keys. For example, if your mod is called skeletons, then name your localization key skeletons.book_of_bones, rather than just book_of_bones.

See also

knights_data/client/localization_english.txt, where the localization keys (and corresponding English-language messages) are defined.

LOCALIZATION.md also has some notes on localization, including how to do a translation to a new language, and some areas for future work.