User Tools

Site Tools

Urban Games

modding:localizations

Localizations

It is possible to provide additional translations for the game. The strings are stored in precompiled .mo libraries. They can be found in the res/strings/ folder. There is a subfolder for each natively supported language: de for German, en for English, …, zh_CN for Simplified Chinese and zh_TW for Traditional Chinese. The folders are named as <language>_<region> where

For example de is the general German and fallback for all other german translations while de_CH is Swiss German and de_AT is Austrian German.

Inside each folder, there is a info.lua file and a LC_MESSAGES/ folder. The info.lua contains some meta information:

function data()
return {
  name = "German",
  locale = "de_CH",
  fontMap = {
    regular = "Lato2OFL/Lato-Regular.ttf",
    bold = "Lato2OFL/Lato-Bold.ttf",
    monoRegular = "Noto/NotoSansMono-Regular.ttf",
    monoBold = "Noto/NotoSansMono-Bold.ttf",
  },
}
end

The properties are:

  • name is the string that is displayed in the settings menu to select the language.
  • locale is the identifier that can be used by other mods to provide compatible translations. In addition, it is used to select the right format for numbers (e.g. decimal point).
  • fontMap is a mapping of font types.

In the LC_MESSAGES/ folder, there are two files:

  • base.mo contains all the basic strings that are used by the UI.
  • res.mo contains all the content related strings, e.g. for object descriptions and mission texts.

A mod that provides additional translations needs to contain a structure analogue to the default languages with the info.lua and the LC_MESSAGES/ folder.

Translation

The translation is a three step process:

  1. Decompiling the .mo files to .po files that are editable
  2. Editing the translation
  3. Compiling the .po files to .mo files that are usable by the game

Decompiling

To start a new translation, it's recommend to base on the default translation. There are some tools that can be used to decompile the .mo files:

  • polib is a python based script library.
  • Poedit is a software to edit .po files that comes with a tool to convert the files.

To convert with that tool, install Poedit. Then you can find a msgunfmt.exe in the installation subfolder Poedit/GettextTools/bin/. Execute path/to/msgunfmt.exe “path/to/xyz.mo” -o “path/to/xyz.po” in a command line interface to convert the file.

Editing

The .po file can be opened by any text editor. For more convenience, programs like Poedit itself can be used to edit the files.

Make sure to set the correct target language. This can be done in Catalogue > Properties at the Language dropdown.

The editor consists of three big areas:

  • The list at the top contains all source and target strings 1. The source strings usually are in english or they are unique keys.
  • The second area contains the source text of the currently selected item 2. Do not modify them!
  • The third area contains the translated text 3. Here you can edit the text. Some texts contain functional elements like %1% or {townName}. They are replaced by some numbers or names ingame. Try to use them equally in the translation too. Some source strings come with different forms for singular and plural. Don't forget to translate all versions that are shown under small tabs.

Compiling

Once the translation should be compiled, either use Poedit File > Compile to MO… or execute path/to/msgunfmt.exe “path/to/xyz.po” -o “path/to/xyz.mo” in a command line interface to convert the file into .mo format.

Updating

With new game releases, there may come new strings too. You can use Poedit to merge new key strings from an updated PO file into yours. Select Catalog > Update from POT file from the menu.

Support additional Languages in Mods

To support additional languages in mods, simply add another table with the identifier from the locale property in the strings.lua:

function data()
return {
  en = {
    ["modname_name"] = "Urban Games Translation Demo",
    ["modname_desc"] = "This mod shows an exemplaric translation",
  },
  de = {
    ["modname_name"] = "Urban Games Übersetzungsdemo",
    ["modname_desc"] = "Diese Mod zeigt eine beispielhafte Übersetzung",
  },
  de_ch = {
    ["modname_name"] = "Urban Games Öbersetzigsdemo",
    ["modname_desc"] = "Die Mod zeigt es guets Bispel för en Öbersetzig",
  },
  ...
}


modding/localizations.txt · Last modified: 2020/06/20 11:13 by yoshi