Files
aego/engine/settings/i18n.go
T
sanspie f22242e5aa
ci / release (push) Successful in 5m5s
ci-platforms / build (amd64, windows, windows-2022) (push) Skipped
ci-platforms / build (arm64, darwin, macos-15) (push) Skipped
ci-platforms / build (amd64, darwin, macos-15-intel) (push) Skipped
ci / checks (push) Successful in 4m41s
ci / build (amd64, linux, ubuntu-24.04) (push) Successful in 7m14s
Stage 11g2–11g3: registry texts, CLI and the site in Russian (D348)
The remaining editor strings and undo step names; component, field, enum, setting, diagnostic and Script API texts under schema.*, enum.*, setting.*, diag.* and api.*; the launcher, the in-game Settings View with a Language setting, the CLI and aego schema show --lang. Every documentation page has a .ru.md translation; the site has a full Russian tree with hreflang, a language switch and ru/llms.txt; aego docs check --lang ru. New doc.tutorial and doc.recipe icons. Fix: an animator restored by a rewind prepares its controller before the replayed step.
2026-10-25 15:31:22 +03:00

85 lines
1.7 KiB
Go

package settings
import (
"sync"
"aego/engine/i18n"
)
// Catalog keys of the settings texts (D348): setting.<id>, setting.<id>.doc, setting.<id>.<choice>, setting.category.<name>.
type descKeys struct {
title, doc, en string
choices map[string]string
}
var (
keyMu sync.RWMutex
descKeyMap = map[string]*descKeys{}
catKeyMap = map[string]string{}
)
func keysOf(d *Desc) *descKeys {
keyMu.RLock()
k := descKeyMap[d.ID]
keyMu.RUnlock()
if k != nil {
return k
}
k = &descKeys{title: "setting." + d.ID, doc: "setting." + d.ID + ".doc", en: d.Label(), choices: map[string]string{}}
keyMu.Lock()
descKeyMap[d.ID] = k
keyMu.Unlock()
return k
}
// Text is the setting's title in the current language.
func (d *Desc) Text() string {
k := keysOf(d)
return i18n.Lookup(k.title, k.en)
}
// Help is the setting's description in the current language.
func (d *Desc) Help() string {
if d.Doc == "" {
return ""
}
return i18n.Lookup(keysOf(d).doc, d.Doc)
}
// ChoiceText is a choice's label in the current language; a choice without a label shows its name.
func (d *Desc) ChoiceText(c Choice) string {
en := c.Label
if en == "" {
en = c.Name
}
if c.Name == "" {
return en
}
k := keysOf(d)
keyMu.RLock()
key, ok := k.choices[c.Name]
keyMu.RUnlock()
if !ok {
key = "setting." + d.ID + "." + c.Name
keyMu.Lock()
k.choices[c.Name] = key
keyMu.Unlock()
}
return i18n.Lookup(key, en)
}
// CategoryText is a settings category in the current language.
func CategoryText(c string) string {
keyMu.RLock()
key, ok := catKeyMap[c]
keyMu.RUnlock()
if !ok {
key = "setting.category." + c
keyMu.Lock()
catKeyMap[c] = key
keyMu.Unlock()
}
return i18n.Lookup(key, c)
}