Kenshi
Kenshi Mod Workshop
You can manage your mods in the Kenshi launcher when you start the game. Workshop mod subscription will only work with Kenshi v0.92.0+
Learn More
 This topic has been pinned, so it's probably important
Koomatzu  [developer] Aug 5, 2016 @ 6:38am
Guide To Translation
(Copied over from our official Lo-Fi forum. I recommend posting any questions in the original post[www.lofigames.com] so that Maykol can answer)

This is a guide explaining in detail how to create translations for Kenshi.

Introduction:
Translations can be done in two ways; as a normal translation (in the 'locale' folder) or as a mod that includes the translation (Mod translation). The difference between them is that the normal one can be changed from a specific list in the launcher (see image below) and allows translations of the launcher text, however, it needs to be placed manually in the game folder. The advantage of being a mod is the easiness that brings the Steam Workshop for uploading and keep it up to date. The decision is up to you.

Image: http://i.imgur.com/HTxr3YO.jpg

Note: It's not recommended to combine both options.

All the displayed strings come from two places: the source code (SC) and and the game data (in the Forgotten Construction Set (FCS)). The SC's strings are mostly messages, titles, and similar stuff. The strings in game data are basically all the game content and the dialogue (everything in the FCS). Both of this are handled different; the SC strings are loaded using a specific library (more on that below) while the game data are loaded similar to a mod (with a different extension).


Format:
The strings to be translated are generated using the 'Boost Locale' library that uses GNU gettext[www.gnu.org] formatting.
There are a bunch of tools and editors to translate and update the files quite easily.
  • Files:
    • There are three types that are handled: pot, po and mo.
    • 'pot' (Portable Object Template) file, which contains a list of all the translatable strings extracted from the sources and game data.
    • 'po' (Portable Object) file contains the translated strings (from the .pot file) for a specific language. This files are created (an can be updated) from a .pot file.
    • 'mo' (Machine Object) file contains the binary-compiled .po translation file.
This last file is the one that needs to be distributed in your translation since it's the one that the game will load. (Only for the SC strings). If you want more info on the format or how it works you can google it.
  • Folder's naming:
    The format for the locale content folder will use the structure 'language[_COUNTRY]' where language is ISO-639[en.wikipedia.org] language name like "en" or "ru", COUNTRY is the ISO-3166[en.wikipedia.org] country identifier like "US" or "DE". The country identifier is optional if you want to make a country specific translation for the same language. Examples: de-DE, zh_HANS, ru, es-ES, en-US.


Tools:
There are a few tools for translating this files. I've recommend Poedit;[poedit.net] it handles creating new translations as well as updating from a pot file.There is also Google Translator Toolkit[translate.google.com] online tool that allows collaboration with multiple people (like a Google Doc file) and some other features. If you want to use this last one, since for some reason it doesn't support the .pot extension, you need to change the extension from .pot to .po from the base files when you upload them.


Getting started:
There are two ways of translating the game data strings (the ones in the FCS); one is creating a normal mod and replace all the names, descriptions, dialogue lines, etc. by hand. The other option is to use the FCS tool to extract all those strings into different .pot files.The advantage of using the extract tool is that it will create a file with non-repeating strings. This is useful mostly for the dialogue part.

Note: Technically both options are compatible with both ways of doing translations as described in the introduction.
  1. Extracting strings:
    Since the SC's strings are already shipped with the game (in the file 'main.pot' that is located in 'Kenshi\locale\en\LC_MESSAGES'), you'll need to decide if you want to extract the game data strings or make a mod directly as commented above. The decision is up to you. This guide will asume that you'll extract the strings from the game data.

    To extract the game data strings follow this steps:
    1. Open FCS
      http://i.imgur.com/jwRjozR.jpg
    2. Load the base mods. (If you load any other mod, the content of that mod will also be extracted and is not recommended)
      http://i.imgur.com/HjD5os4.jpg
    3. Press the toolbar button 'Translations'
      http://i.imgur.com/63S6wyl.jpg
    4. Press 'Export' button.
      http://i.imgur.com/0QHMvNF.jpg
    Once complete it will create a bunch of .pot files in Kenshi\__translations\base folder.
    http://i.imgur.com/ZcfWUDN.jpg

    The gamedata.pot contains all the items, buildings, races, towns, etc. names and descriptions (if they have). In the dialogue folder there is a list of .pot files, one for each dialogue conversation. This way it easier to have context on each string.
    http://i.imgur.com/QfwbqQV.jpg

    Important note: There are text files in the data folder like 'tips.txt', 'namesF.txt', etc. that need to be directly translated (without using the .pot/.po format) (See part 4 for how to include them).

  2. Translating:
    You'll need to create a translation (.po) file for each .pot file. You can use the Poedit or any similar tool to do this.

    Translation notes:
    • In the strings, the content inside braces ({}) represents some value that is replaced in game with some other content. It can be from numbers, names, actions, etc. The braces plus their content should not be modified, although the can be placed in different location in the text. E.g.: "Lockpicking (Chance {1}%)" in Spanish could be translated as: "Forzando cerradura ({1}% de probabilidad)".
      Note: This type of strings only are on the strings in 'main.pot'
    • Some lines in the dialogue contains strings in between slashes (/) like /HELL/ or /YOUTHERE/, this represent word swaps. This word swaps are randomly or context-based replaced in game by other words. Similar to the braces, this should be maintained the same inside and can be moved.
      Note: All the word swaps are in __translations\base\dialogue\_word_swaps.pot if you extracted the strings using the FCS.

    Note 1: Before you create the files, read the next step that explains the needed folder structure for the game.
    Note 2: All non-translated strings (empty string "") in the .po files will be show the original string in English (both from the main.po and the game data extracted/build from the FCS).

  3. Packing:
    Once you finished translating or want to make a partial release, you'll need to build the game data strings to create the .translation file and place all the files in the corresponding folders.
    1. Create the final folder (output folder):
      - If you are creating a normal translation, create a folder in Kenshi\locale\ with the name in the format specified in the Format/Folders section above.
      E.g.: Kenshi\locale\fr-FR\
      - If you are creating a mod translation, create a folder named locale in your mod folder (e.g. Kenshi\mods\<mytranslationmod>) with a folder inside with the name in the format specified in the Format/Folders section above.
      E.g.: Kenshi\mods\<mytranslationmod>\locale\fr-FR\

    2. Building the game data translations:
      Note: If you are making the translations directly in a mod using the FCS, ignore this step.
      1. Create a folder under the directory Kenshi\__translations with the name in the format specified in the Format/Folders section above. (E.g. fr-FR)
      2. Place the translated gamedata.po file in that folder and the dialogue .po translation files in the dialogue folder in that directory.
        http://i.imgur.com/QfwbqQV.jpg
      3. Open the FCS and open the translation window (see steps 1.1-1.3 how to do this)
      4. Select the language from the list (if it's not there press the refresh button next to it) and press the 'Build' button.
        http://i.imgur.com/NDW8gmZ.jpg
      5. This will generate a .translation file in that folder.
        http://i.imgur.com/4VEFBmV.jpg

    3. Copy the translation result files:
      1. Copy the .translation file in the output folder (created in step 3.1). If you didn't extracted/built the files using the FCS tool, ignore this step.
      2. Create a folder under the output folder (step 3.1) named LC_MESSAGES
      3. Copy the translated main.mo file (note that is the .MO file, NOT the .po file) into the LC_MESSAGES folder.

    The output folder should look something like this:
    - Normal translation
    CODE: SELECT ALL
    Kenshi
    \---locale
    \---ru
    | ru.translation
    |
    \---LC_MESSAGES
    main.mo


    - Mod translation
    CODE: SELECT ALL
    Kenshi
    \---mods
    \---my_russian_translation
    | my_russian_translation.mod
    |
    \---locale
    \---ru
    | ru.translation
    |
    \---LC_MESSAGES
    main.mo

  4. Extra content
    Because the fonts shipped with the game (and maybe other content) doesn't support all languages, you'll probably need to modify or add new content to your mod/translation. Luckily both type (normal and mod translation) support modifying or adding extra game files easily:
    • For Mod translations, since it's works the same as a mod, you just need to create the folders on the mod folder using the same structure and placing the files you want to add or replace. (E.g.: Kenshi\mod\mymod\ ~= Kenshi\data\)
    • For Normal translations, the output folder will behave the same as the mod folder. (E.g.: Kenshi\locale\ru\ ~= Kenshi\data\)

    The easiest way of explaining this is with an example.
    In this case what I'm going to do is add extra fonts to support Russian alphabet.
    If you check the current fonts in the game (Kenshi/data/gui/fonts/), only one of them supports Cyrillic alphabet (Exo2), however, if you check kenshi_fonts.xml (this is the file that is loaded by the game and contains all the information of the fonts) for that font it only uses the character code range 32 to 126 which don't include the Cyrillic characters. To fix this we need to add those character ranges.

    - Before:
    CODE: SELECT ALL
    <Code range="32 126"/>

    - After:
    CODE: SELECT ALL
    <Code range="32 126"/>
    <Code range="1024 1279"/>

    Note: I don't know if that includes all the needed characters, for now let's assume it is enough.

    For the two other fonts used, we need to choose new ones (https://fonts.google.com/ is a good source of nice free fonts) and modify kenshi_fonts.xml to use those new fonts (and also add the character codes ranges). Once we finish with that, the last step is to copy them to the locale/mod output folder.

    The result will be something like this:

    - Normal translation
    CODE: SELECT ALL
    Kenshi
    \---locale
    \---ru
    | ru.translation
    | tips.txt
    | namesF.txt
    | namesM.txt
    | namesMF.txt
    |
    +---gui
    | \---fonts
    | kenshi_fonts.xml
    | pretty_font_with_cyrilic_chars.ttf
    | some_font_with_cyrilic_chars.ttf
    |
    \---LC_MESSAGES
    main.mo

    - Mod translation
    CODE: SELECT ALL
    Kenshi
    \---mods
    \---russian
    | russian.mod
    | tips.txt
    | namesF.txt
    | namesM.txt
    | namesMF.txt
    |
    +---gui
    | \---fonts
    | kenshi_fonts.xml
    | pretty_font_with_cyrilic_chars.ttf
    | some_font_with_cyrilic_chars.ttf
    |
    \---locale
    \---ru
    | ru.translation
    |
    \---LC_MESSAGES
    main.mo


    Note 1: I didn't include the Exo2 fonts since they are already in the game data folder.
    Note 2: I've included tips.txt, namesF.txt, etc. as an example of other files that can be modified.


  5. Share and profit?
    Upload it to Steam Workshop, to another site or do whatever you want with it.

General comments:
The locale folder with name 'en' will be ignored since the game is already in English. You can still create a country variation for English. (I.e.: en-US, en-GB, etc.)
Last edited by Koomatzu; Aug 5, 2016 @ 7:05am