-
Notifications
You must be signed in to change notification settings - Fork 0
Internationalization
Updated for v1.1.126. The 19-language catalog and compiled message catalogs are synchronized as part of the release preparation.
OpenCaptive supports 19 languages with full UI translation coverage using a gettext-compatible PO file system.
| Code | Language |
|---|---|
| en | English |
| sv | Svenska |
| cs | Cestina |
| da | Dansk |
| de | Deutsch |
| es | Espanol |
| fi | Suomi |
| fr | Francais |
| hu | Magyar |
| it | Italiano |
| ja | Japanese |
| ko | Korean |
| nl | Nederlands |
| no | Norsk |
| pl | Polski |
| pt | Portugues |
| ro | Romana |
| ru | Russian |
| zh | Chinese |
All translatable strings are wrapped with the _() macro:
#define _(s) i18n_get(s)This calls i18n_get(), which performs a linear search through the loaded translation table (up to 512 entries of 256 characters each).
#define I18N_MAX_ENTRIES 512
#define I18N_MAX_MSGLEN 256
typedef struct {
char msgid[I18N_MAX_MSGLEN];
char msgstr[I18N_MAX_MSGLEN];
} I18nEntry;
typedef struct {
char lang[16];
I18nEntry entries[I18N_MAX_ENTRIES];
int count;
} I18nTable;void i18n_init(const char *lang_override);
void i18n_free(void);
const char *i18n_get(const char *msgid);
const char *i18n_get_lang(void);At startup, i18n_init determines the language in this order:
-
CLI override:
--lang <code>command-line argument (passed aslang_override). -
SDL3 auto-detection:
SDL_GetPreferredLocales()queries the operating system locale. -
Fallback: English (no PO file loaded;
i18n_getreturns the msgid verbatim).
Translation files use the standard gettext .po format, stored in the po/ directory:
-
Source files:
po/<lang>.po(e.g.,po/sv.po,po/ja.po) -
Template:
po/messages.pot(POT template for generating new translations)
The runtime loads .po files directly — no .mo compilation step is needed. The loader searches for PO files first relative to the SDL base path, then the current working directory. It handles escape sequences (\n, \t, \\, \") and multi-line msgid/msgstr via continuation strings.
All user-facing text is translatable:
- Start menu labels and descriptions
- Settings panel items
- Building interaction dialogue
- Shop interface
- NPC dialogue
- Combat messages
- All HUD and status text
The built-in bitmap font uses 5-column, 7-row glyphs covering A-Z, a-z, 0-9, and common punctuation. It includes:
- UTF-8 decoding: multi-byte UTF-8 sequences are decoded to Unicode codepoints.
- Accented character fallback: Unicode accented characters are mapped to their ASCII base character for rendering (e.g., e with accent maps to plain e).
The start menu uses DejaVu Sans Mono Bold TTF rendering at 36pt, 18pt, and 14pt sizes, which supports the full Unicode range needed for all 19 languages.
The language selector in the Settings panel cycles through all 19 languages using Left/Right arrow keys. The lang_index field in StartMenu tracks the current selection. Changing the language reloads the translation table.
- Copy
po/messages.pottopo/<code>.po. - Translate all
msgstrentries. - Add the language code to the
LANG_COUNTarray instart_menu.c.
- Header:
include/i18n.h - Implementation:
src/data/i18n.c - Translations:
po/*.po - Template:
po/messages.pot