feat(i18n): enrich service state snapshot
All checks were successful
Security Scan / security (push) Successful in 13s
Test / test (push) Successful in 2m30s

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 13:06:07 +00:00
parent 730b6166a1
commit d868f21ab2
3 changed files with 19 additions and 1 deletions

View file

@ -182,6 +182,8 @@ func CurrentDebug() bool {
func State() ServiceState {
return defaultServiceValue(ServiceState{
Language: "en",
RequestedLanguage: "",
LanguageExplicit: false,
AvailableLanguages: []string{},
Mode: ModeNormal,
Fallback: "en",

View file

@ -193,6 +193,12 @@ func TestServiceCurrentStateAliases(t *testing.T) {
if got, want := svc.CurrentState(), svc.State(); len(got.AvailableLanguages) != len(want.AvailableLanguages) || len(got.Handlers) != len(want.Handlers) {
t.Fatalf("CurrentState() = %+v, want %+v", got, want)
}
if got, want := svc.CurrentState().RequestedLanguage, svc.State().RequestedLanguage; got != want {
t.Fatalf("CurrentState().RequestedLanguage = %q, want %q", got, want)
}
if got, want := svc.CurrentState().LanguageExplicit, svc.State().LanguageExplicit; got != want {
t.Fatalf("CurrentState().LanguageExplicit = %t, want %t", got, want)
}
}
func TestServiceCurrentStateAliasesReturnCopies(t *testing.T) {
@ -249,6 +255,8 @@ func TestServiceStateString(t *testing.T) {
for _, want := range []string{
"ServiceState{",
"language=",
"requested=",
"explicit=",
"fallback=",
"mode=",
"available=",

View file

@ -8,6 +8,8 @@ import (
// copy-safe snapshot.
type ServiceState struct {
Language string
RequestedLanguage string
LanguageExplicit bool
AvailableLanguages []string
Mode Mode
Fallback string
@ -38,8 +40,10 @@ func (s ServiceState) String() string {
handlers = "[" + core.Join(", ", names...) + "]"
}
return core.Sprintf(
"ServiceState{language=%q fallback=%q mode=%s formality=%s location=%q direction=%s rtl=%t debug=%t available=%s handlers=%d types=%s}",
"ServiceState{language=%q requested=%q explicit=%t fallback=%q mode=%s formality=%s location=%q direction=%s rtl=%t debug=%t available=%s handlers=%d types=%s}",
s.Language,
s.RequestedLanguage,
s.LanguageExplicit,
s.Fallback,
s.Mode,
s.Formality,
@ -57,6 +61,8 @@ func (s *Service) State() ServiceState {
if s == nil {
return ServiceState{
Language: "en",
RequestedLanguage: "",
LanguageExplicit: false,
AvailableLanguages: []string{},
Mode: ModeNormal,
Fallback: "en",
@ -85,6 +91,8 @@ func (s *Service) State() ServiceState {
return ServiceState{
Language: s.currentLang,
RequestedLanguage: s.requestedLang,
LanguageExplicit: s.languageExplicit,
AvailableLanguages: langs,
Mode: s.mode,
Fallback: s.fallbackLang,