feat(i18n): enrich service state snapshot
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
730b6166a1
commit
d868f21ab2
3 changed files with 19 additions and 1 deletions
2
i18n.go
2
i18n.go
|
|
@ -182,6 +182,8 @@ func CurrentDebug() bool {
|
|||
func State() ServiceState {
|
||||
return defaultServiceValue(ServiceState{
|
||||
Language: "en",
|
||||
RequestedLanguage: "",
|
||||
LanguageExplicit: false,
|
||||
AvailableLanguages: []string{},
|
||||
Mode: ModeNormal,
|
||||
Fallback: "en",
|
||||
|
|
|
|||
|
|
@ -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=",
|
||||
|
|
|
|||
10
state.go
10
state.go
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue