Files
aego/schema/i18n.go
T
sanspie 50be5c04bc
ci-platforms / darwin amd64 smoke (push) Skipped
GitHub / linux amd64 native GitHub-hosted native CI: success
ci-platforms / windows amd64 smoke (push) Skipped
GitHub / windows amd64 native GitHub-hosted native CI: success
GitHub / darwin arm64 native GitHub-hosted native CI: success
GitHub / darwin amd64 native GitHub-hosted native CI: success
ci / checks (push) Failing after 1h21m34s
ci / native-authoring (push) Skipped
ci-platforms / darwin arm64 smoke (push) Skipped
github-native / gitea-pending (push) Skipped
github-native / darwin amd64 native (push) Skipped
github-native / linux amd64 native (push) Skipped
github-native / windows amd64 native (push) Skipped
github-native / darwin arm64 native (push) Skipped
github-native / gitea-result (push) Skipped
ci / build (amd64, linux, ubuntu-24.04) (push) Successful in 12m4s
ci / release (push) Skipped
Stage 12.5: Art Workspace and asset authoring
Add dockable Art tools, animation and previews, guarded asset workflows,
and the Web Asset Studio built on the shared Art Core. Expand English and
Russian documentation, interactive Try scenes, examples and editor icons.

Add audio waveform navigation, source analysis, guarded previews and a
browser Worker mixer. Preserve source changes and recovery with bounded
checks, and strengthen native, browser and interoperability CI.

Prepare version 0.12.5 and manually built native artifact candidates.
Fix the production site image demo build dependency.
Reuse immutable scene indices when capturing keyframes.
Wait for real Persist save/load completion in component tests.
Stabilize browser Game View captures outside pointer hover.
Aseprite interchange and persistent Audio EDL recovery remain limited;
the artifact workflow does not publish releases or change stable.
2026-11-15 10:37:50 +03:00

149 lines
4.1 KiB
Go

package schema
import (
"strings"
"sync"
"aego/engine/i18n"
)
// Catalog keys of the schema texts (D348): schema.<type>, schema.<type>.doc, schema.<type>.<field>, schema.<type>.<field>.doc, enum.<enum>.<value>.
type typeKeys struct{ title, doc, en string }
type fieldKeys struct{ label, doc, en string }
var (
typeKeyCache sync.Map
fieldKeyCache sync.Map
enumKeyCache sync.Map
)
func keysOfType(td *TypeDescriptor) *typeKeys {
if k, ok := typeKeyCache.Load(td); ok {
return k.(*typeKeys)
}
k := &typeKeys{title: TypeKey(td), doc: TypeKey(td) + ".doc", en: EnglishTitle(td)}
typeKeyCache.Store(td, k)
return k
}
func keysOfField(td *TypeDescriptor, fd *FieldDescriptor) *fieldKeys {
if k, ok := fieldKeyCache.Load(fd); ok {
return k.(*fieldKeys)
}
k := &fieldKeys{label: FieldKey(td, fd), doc: FieldKey(td, fd) + ".doc", en: Label(fd)}
fieldKeyCache.Store(fd, k)
return k
}
// TypeKey is the catalog key of a type's display name.
func TypeKey(td *TypeDescriptor) string { return "schema." + td.FullName }
// FieldKey is the catalog key of a field's label.
func FieldKey(td *TypeDescriptor, fd *FieldDescriptor) string {
return "schema." + td.FullName + "." + fd.Name
}
// EnumKey is the catalog key of an enum value's label.
func EnumKey(enum, value string) string { return "enum." + enum + "." + value }
// Title is EnglishTitle in the current language.
func Title(td *TypeDescriptor) string {
if td.Kind == TypeScript {
return EnglishTitle(td)
}
k := keysOfType(td)
return i18n.Lookup(k.title, k.en)
}
// EnglishTitle is a type's DisplayName, else the humanized last part of its name.
func EnglishTitle(td *TypeDescriptor) string {
if td.DisplayName != "" {
return td.DisplayName
}
return Humanize(td.FullName[strings.LastIndexByte(td.FullName, '.')+1:])
}
// SearchNames is shared by the editor creation palette and documentation.
// Technical IDs, all shipped translations and former display names remain
// searchable regardless of the active UI language.
func SearchNames(td *TypeDescriptor) []string {
names := []string{td.FullName, EnglishTitle(td)}
names = append(names, td.SearchAliases...)
names = append(names, i18n.Default().Translations(TypeKey(td))...)
out := make([]string, 0, len(names))
seen := make(map[string]bool, len(names))
for _, name := range names {
name = strings.TrimSpace(name)
key := strings.ToLower(name)
if key != "" && !seen[key] {
seen[key] = true
out = append(out, name)
}
}
return out
}
// TypeDoc is a type's description in the current language.
func TypeDoc(td *TypeDescriptor) string {
if td.Doc == "" || td.Kind == TypeScript {
return td.Doc
}
return i18n.Lookup(keysOfType(td).doc, td.Doc)
}
// FieldLabel is Label in the current language.
func FieldLabel(td *TypeDescriptor, fd *FieldDescriptor) string {
if td.Kind == TypeScript {
return Label(fd)
}
k := keysOfField(td, fd)
return i18n.Lookup(k.label, k.en)
}
// FieldHelp is a field's description in the current language.
func FieldHelp(td *TypeDescriptor, fd *FieldDescriptor) string {
if fd.Doc == "" || td.Kind == TypeScript {
return fd.Doc
}
return i18n.Lookup(keysOfField(td, fd).doc, fd.Doc)
}
// EnumLabel is the label of the i-th enum value of a field; English shows the value's name.
func EnumLabel(fd *FieldDescriptor, i int) string {
if fd.EnumName == "" {
return fd.Enum[i].Name
}
var keys []string
if k, ok := enumKeyCache.Load(fd); ok {
keys = k.([]string)
} else {
for _, ev := range fd.Enum {
keys = append(keys, EnumKey(fd.EnumName, ev.Name))
}
enumKeyCache.Store(fd, keys)
}
return i18n.Lookup(keys[i], fd.Enum[i].Name)
}
// FieldTip is the field's tooltip: its description in the current language, or a tooltip set apart from it.
func FieldTip(td *TypeDescriptor, fd *FieldDescriptor) string {
if fd.Hints.Tooltip == fd.Doc {
return FieldHelp(td, fd)
}
return fd.Hints.Tooltip
}
var categoryKeys sync.Map
// CategoryLabel is a field category, such as Runtime, in the current language.
func CategoryLabel(c string) string {
k, ok := categoryKeys.Load(c)
if !ok {
k = "schema.category." + c
categoryKeys.Store(c, k)
}
return i18n.Lookup(k.(string), c)
}