ludic.ui, ludic.i18n: frame_allocs to 0 - a wrap, an ellipsis, a tooltip's lines, a text-shadow's colour and a range's value kept by what made them; pointer events from a ring; inline text joined through the memo; the pool's and the state's lists through ui_kept; parse, memo miss, pool miss, lazy start and template errors declared; the translation cache clears in place

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-28 16:41:47 +03:00
parent 629579123a
commit 429e419327
71 changed files with 365 additions and 155 deletions

View file

@ -1,5 +1,6 @@
# langs.ludic - where languages come from, later ones replacing earlier ones with the same code:
# <lang_dir>/languages.txt (one code per line, # a comment) and every .po in the mod folder
@alloc_ok("once at start: the shipped and dropped-in languages found")
export function i18n_init(i18n_st: mut I18nState) -> void {
i18n_st.codes = new []string
i18n_st.names = new []string

View file

@ -46,6 +46,7 @@ function best_of(i18n_st: mut I18nState, head: int, next: words, s: string, best
return b
}
@alloc_ok("a translation cache miss (L): once per distinct text")
function pattern(i18n_st: mut I18nState, s: string, depth: int) -> string {
i18n_st.hit = false
if i18n_st.pat_n == 0 { return s }

View file

@ -20,6 +20,7 @@ function entry_put(e: PoEntry, mode: int, s: string) -> void {
if mode == 4 { e.forms[len(e.forms) - 1] = e.forms[len(e.forms) - 1] + s }
}
@alloc_ok("on a language change: a .po read")
export function i18n_parse(text: string) -> []PoEntry {
let r = new []PoEntry
let lines = lines_of(text)
@ -81,6 +82,7 @@ function unquote(line: string, from: int) -> string {
}
# a header field out of the msgstr "" block: "X-Language-Name: Türkçe\n"
@alloc_ok("on a language change: a .po's header read")
export function i18n_header(text: string, field: string) -> string {
var n = len(text)
if n > 4000 { n = 4000 }

View file

@ -7,13 +7,16 @@ export function L(i18n_st: mut I18nState, s: string) -> string {
let r = whole(i18n_st, s)
if Dict.size(i18n_st.cache) >= CACHE_MAX {
Dict.clear(i18n_st.cache)
i18n_st.cache_out = new []string
List.clear(i18n_st.cache_out)
}
@alloc_ok("a translation cache miss: the entry is kept, up to CACHE_MAX")
Dict.set(i18n_st.cache, s, len(i18n_st.cache_out))
@alloc_ok("a translation cache miss: as above")
push(i18n_st.cache_out, r)
return r
}
@alloc_ok("a translation cache miss (L): once per distinct text, bounded by CACHE_MAX")
function whole(i18n_st: mut I18nState, s: string) -> string {
let n = len(s)
if n == 0 { return s }
@ -37,6 +40,7 @@ function whole(i18n_st: mut I18nState, s: string) -> string {
}
# a paragraph built from sentences, one at a time; English stays where a sentence is unknown
@alloc_ok("a translation cache miss (L): once per distinct text")
function sentences(i18n_st: mut I18nState, s: string) -> string {
let n = len(s)
var r = ""

View file

@ -27,6 +27,7 @@ export function i18n_use(i18n_st: mut I18nState, code: string) -> void {
}
# a .po's text as the lookups, whatever the language is called (a test, a file from elsewhere)
@alloc_ok("on a language change: the language's messages read in")
export function i18n_load_text(i18n_st: mut I18nState, text: string) -> void {
let es = i18n_parse(text)
i18n_st.exact = Dict.new()