From 4cd54a58f8fa5b07da8e6aaa420527bfb3e66dc3 Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Thu, 21 Oct 2021 16:10:15 +0200 Subject: [PATCH] Remove fallback to base language in case of missing translation --- pkg/locale/locale.go | 12 +++++++++--- pkg/locale/service.go | 7 ++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/pkg/locale/locale.go b/pkg/locale/locale.go index 4578018b0..9f66720a4 100644 --- a/pkg/locale/locale.go +++ b/pkg/locale/locale.go @@ -74,10 +74,14 @@ func (l *Language) t(ns, key string, rr ...string) string { return strings.NewReplacer(rr...).Replace(msg) } + // If translation is not found, try with language + // this language extends if l.extends != nil { return l.extends.t(ns, key, rr...) } + // In case of untranslated string / missing translations, + // translation key is returned return key } @@ -95,10 +99,12 @@ func (l *Language) tResource(ns, key string, rr ...string) string { return strings.NewReplacer(rr...).Replace(rt.Msg) } - if l.extends != nil { - return l.extends.tResource(ns, key, rr...) - } + // When translating resources we do not utilize + // language extensions like with static translations + // In case of untranslated string / missing translations, + // only empty string is returned (in contrast to static translations + // where a string with key is returned return "" } diff --git a/pkg/locale/service.go b/pkg/locale/service.go index 30b60fcd4..e9d680513 100644 --- a/pkg/locale/service.go +++ b/pkg/locale/service.go @@ -438,6 +438,8 @@ func (svc *service) t(tag language.Tag, ns, key string, rr ...string) string { } } + // In case of a missing language, translation + // key is returned return key } @@ -449,7 +451,10 @@ func (svc *service) tResource(tag language.Tag, ns, key string, rr ...string) st } } - return key + // In case of a missing language, only empty string is + // returned (in contrast to static translations + // where a string with key is returned) + return "" } func hasTag(t language.Tag, tt []language.Tag) bool {