ludic/packages/ludic.i18n/ports.ludic
Orkuncakilkaya 1667d7f16e ludic.i18n: a language's lookups kept once read; switching back restores them
i18n_use re-read and re-parsed the .po on every change of language (ev_SettingsChanged, SetLang)
and dropped the old tables for good: the play of 22 minutes left lines_of 650 KB, fs_read_text
409 KB, PoEntry 113 KB and unquote 273 KB unreachable, and three of its @alloc_ok sites were
declared but unbounded. Each language's tables are now filed by index once built (tables.ludic,
I18nTables) and put back by reference; a new probe (i18n_init) or a different file for a code
(lang_add) reads it again.

Test: a language switched back to is its kept tables, not its file read again; a new probe reads
it (9 tests pass).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 12:21:53 +03:00

56 lines
2.8 KiB
Text

# ports.ludic - what the languages ask the game: where a player's own .po files are, a code that
# overrides the choice (a test in a language), and the overlay's font atlas, which is the game's
export port I18nWorld {
mod_dir: fn() -> string = fn i18n__no_dir # "" is no mod folder
forced: fn() -> string = fn i18n__no_code # "" is the code asked for
font_ready: fn() -> bool = fn i18n__no # is there an overlay to load a font into
set_font: fn(string) -> bool = fn i18n__no_font # load this atlas directory; false if it could not
}
function i18n__no_dir() -> string { return "" }
function i18n__no_code() -> string { return "" }
function i18n__no() -> bool { return false }
function i18n__no_font(dir: string) -> bool { return false }
export state I18nState {
lang_dir: string = "assets/lang"
font_default: string = "assets/kit/font"
on: bool = false # a language other than English is drawing
cur: string = "en"
codes: []string = null # every language found, "en" first
names: []string = null
paths: []string = null
fonts: []string = null # a font atlas directory, "" for the game's own
font_now: string = ""
exact: Dict = null # msgid -> index into out
out: []string = null
lits: []string = null # every pattern's literal pieces, one run per pattern
pat_out: []string = null
pat_l0: words = null # where a pattern's pieces start in lits
pat_nl: words = null # how many pieces (holes + 1)
pat_sc: words = null # bytes of English it pins down: more is a better match
pat_ph: words = null # by piece: the hole number that follows it
pat_n: int = 0
pfx: Dict = null # a pattern's first four bytes -> its chain head + 1
sfx: Dict = null # else its last four
gen_head: int = 0 # else the short list, tried on short strings only
nx_p: words = null
nx_s: words = null
nx_g: words = null
cache: Dict = null # English as drawn -> index into cache_out
cache_out: []string = null
caps: []string = null
hit: bool = false
plural: Dict = null # a plural msgid (the singular) -> index into forms / 3
forms: []string = null # three forms per entry, "" where the file has fewer
plural_rule: int = 0 # PL_*
tabs: []I18nTables = null # by language: its lookups once read, kept for the next switch
}
# where the shipped languages are (a directory with languages.txt and <code>.po), and the atlas a
# language with no X-Font draws in
export function i18n_config(i18n_st: mut I18nState, dir: string, default_font: string) -> void {
i18n_st.lang_dir = dir
i18n_st.font_default = default_font
i18n_st.codes = null
}