From 10d4152ad6a0d506298fceed93ccfac1eb155f6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20Jerman?= Date: Wed, 15 Sep 2021 11:53:52 +0200 Subject: [PATCH] Default resource translation to key value if missing --- compose/types/locale.gen.go | 14 ++++++++++++++ .../assets/templates/gocode/locale/types.go.tpl | 2 ++ pkg/locale/locale.go | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/compose/types/locale.gen.go b/compose/types/locale.gen.go index d820583d8..b72d96753 100644 --- a/compose/types/locale.gen.go +++ b/compose/types/locale.gen.go @@ -124,6 +124,8 @@ func (r *ModuleField) DecodeTranslations(tt locale.ResourceTranslationIndex) { var aux *locale.ResourceTranslation if aux = tt.FindByKey(LocaleKeyModuleFieldLabel.Path); aux != nil { r.Label = aux.Msg + } else { + r.Label = LocaleKeyModuleFieldLabel.Path } r.decodeTranslationsValidatorError(tt) } @@ -172,6 +174,8 @@ func (r *Module) DecodeTranslations(tt locale.ResourceTranslationIndex) { var aux *locale.ResourceTranslation if aux = tt.FindByKey(LocaleKeyModuleName.Path); aux != nil { r.Name = aux.Msg + } else { + r.Name = LocaleKeyModuleName.Path } r.decodeTranslations(tt) @@ -221,12 +225,18 @@ func (r *Namespace) DecodeTranslations(tt locale.ResourceTranslationIndex) { var aux *locale.ResourceTranslation if aux = tt.FindByKey(LocaleKeyNamespaceName.Path); aux != nil { r.Name = aux.Msg + } else { + r.Name = LocaleKeyNamespaceName.Path } if aux = tt.FindByKey(LocaleKeyNamespaceSubtitle.Path); aux != nil { r.Meta.Subtitle = aux.Msg + } else { + r.Meta.Subtitle = LocaleKeyNamespaceSubtitle.Path } if aux = tt.FindByKey(LocaleKeyNamespaceDescription.Path); aux != nil { r.Meta.Description = aux.Msg + } else { + r.Meta.Description = LocaleKeyNamespaceDescription.Path } } @@ -282,9 +292,13 @@ func (r *Page) DecodeTranslations(tt locale.ResourceTranslationIndex) { var aux *locale.ResourceTranslation if aux = tt.FindByKey(LocaleKeyPageTitle.Path); aux != nil { r.Title = aux.Msg + } else { + r.Title = LocaleKeyPageTitle.Path } if aux = tt.FindByKey(LocaleKeyPageDescription.Path); aux != nil { r.Description = aux.Msg + } else { + r.Description = LocaleKeyPageDescription.Path } r.decodeTranslations(tt) diff --git a/pkg/codegen-v3/assets/templates/gocode/locale/types.go.tpl b/pkg/codegen-v3/assets/templates/gocode/locale/types.go.tpl index e4a41fd40..34fe7a47e 100644 --- a/pkg/codegen-v3/assets/templates/gocode/locale/types.go.tpl +++ b/pkg/codegen-v3/assets/templates/gocode/locale/types.go.tpl @@ -88,6 +88,8 @@ func (r *{{ .Resource }}) DecodeTranslations(tt locale.ResourceTranslationIndex) {{- if not .Custom }} if aux = tt.FindByKey(LocaleKey{{ $Resource }}{{coalesce (export .Name) (export .Path) }}.Path); aux != nil { r.{{ .Field }} = aux.Msg + } else { + r.{{ .Field }} = LocaleKey{{ $Resource }}{{coalesce (export .Name) (export .Path) }}.Path } {{- end}} {{- end}} diff --git a/pkg/locale/locale.go b/pkg/locale/locale.go index 557a9b912..f96bb4362 100644 --- a/pkg/locale/locale.go +++ b/pkg/locale/locale.go @@ -99,7 +99,7 @@ func (l *Language) tResource(ns, key string, rr ...string) string { return l.extends.tResource(ns, key, rr...) } - return "" + return key } // resourceTranslations returns all resource translations for the specified resource