foxygit / Hush Log in
commits tags

/src/lang.h · 2.43 KB

raw
#ifndef HUSH_LANG_H
#define HUSH_LANG_H

#include <stdbool.h>

/* All user-facing UI text (status bar, quit-confirm and shortcuts-help modals) goes through
   this table, so a translation only requires a new assets/lang/<code>.lang file -- no source
   changes. Every StringId has a compiled-in English fallback (see lang.c), used for any key
   missing from the loaded language file, so a partial translation never shows blank text. */
typedef enum {
    STR_UNTITLED,
    STR_STATUSBAR_LINE,
    STR_STATUSBAR_LINES,
    STR_QUIT_TITLE,
    STR_QUIT_SAVE,
    STR_QUIT_DISCARD,
    STR_QUIT_CANCEL,
    STR_QUIT_TITLE_OPEN,
    STR_QUIT_SAVE_OPEN,
    STR_QUIT_DISCARD_OPEN,
    STR_OPEN_TITLE,
    STR_OPEN_CONFIRM,
    STR_OPEN_ERROR,
    STR_HELP_TITLE,
    STR_HELP_ARROWS,
    STR_HELP_SHIFT_ARROWS,
    STR_HELP_MOUSE_DRAG,
    STR_HELP_SAVE,
    STR_HELP_OPEN,
    STR_HELP_COPY_PASTE,
    STR_HELP_UNDO_REDO,
    STR_HELP_QUIT,
    STR_HELP_THIS_HELP,
    STR_HELP_ENTER,
    STR_HELP_BACKSPACE_DELETE,
    STR_HELP_HOME_END,
    STR_HELP_SOURCE_VIEW,
    STR_HELP_ZOOM,
    STR_HELP_QUICK_INSERT,
    STR_HELP_CLOSE,
    STR_SOURCE_HINT,
    STR_BLOCK_H1,
    STR_BLOCK_H2,
    STR_BLOCK_H3,
    STR_BLOCK_H4,
    STR_BLOCK_H5,
    STR_BLOCK_H6,
    STR_BLOCK_BULLET,
    STR_BLOCK_NUMBERED,
    STR_BLOCK_QUOTE,
    STR_BLOCK_CODE,
    STR_BLOCK_TASK,
    STR_BLOCK_HR,
    STR_BLOCK_IMAGE,
    STR_BLOCK_TABLE,
    STR_QUICK_INSERT_EMPTY,
    STR_COUNT,
} StringId;

/* Loads assets/lang/<code>.lang (e.g. code="sv" -> ASSETS_DIR "/lang/sv.lang"). Any key not
   present in the file (or if the file can't be opened at all, e.g. an unknown language code)
   silently keeps the built-in English default for that string -- never fatal. Call once at
   startup, before the main loop; the loaded strings live for the rest of the process. */
void lang_load(const char *code);
void lang_free(void);

/* Returns the current text for `id` -- the loaded translation if set, else the English
   default. The returned pointer is valid for the remaining lifetime of the process, so it's
   safe to hand directly to Clay without a per-frame copy. */
const char *lang_get(StringId id);

/* Exposed for headless unit testing of the line parser without touching a real file. Returns
   true if the line set a recognized key; false for comments/blank/unrecognized/malformed
   lines (never fatal, same contract as config_parse_line). */
bool lang_parse_line(const char *line, int len);

#endif