From a50c64747ea3de762193830d8ed7ceb2ced6bf06 Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Wed, 15 Sep 2021 06:48:10 +0200 Subject: [PATCH] Rename TR* to TResource* for clarity --- compose/service/locale.gen.go | 12 +++++------ compose/service/locale.go | 10 +++++----- .../templates/gocode/locale/service.go.tpl | 2 +- .../templates/gocode/locale/types.go.tpl | 2 +- pkg/locale/locale.go | 8 ++++---- pkg/locale/service.go | 20 +++++++++---------- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/compose/service/locale.gen.go b/compose/service/locale.gen.go index bb914c10c..4c0ef2550 100644 --- a/compose/service/locale.gen.go +++ b/compose/service/locale.gen.go @@ -125,7 +125,7 @@ func (svc resourceTranslation) Module(ctx context.Context, namespaceID uint64, I Resource: res.ResourceTranslation(), Lang: tag.String(), Key: k.Path, - Msg: svc.locale.TRFor(tag, res.ResourceTranslation(), k.Path), + Msg: svc.locale.TResourceFor(tag, res.ResourceTranslation(), k.Path), }) } @@ -153,7 +153,7 @@ func (svc resourceTranslation) Namespace(ctx context.Context, ID uint64) (locale Resource: res.ResourceTranslation(), Lang: tag.String(), Key: k.Path, - Msg: svc.locale.TRFor(tag, res.ResourceTranslation(), k.Path), + Msg: svc.locale.TResourceFor(tag, res.ResourceTranslation(), k.Path), }) k = types.LocaleKeyNamespaceSubtitle @@ -161,7 +161,7 @@ func (svc resourceTranslation) Namespace(ctx context.Context, ID uint64) (locale Resource: res.ResourceTranslation(), Lang: tag.String(), Key: k.Path, - Msg: svc.locale.TRFor(tag, res.ResourceTranslation(), k.Path), + Msg: svc.locale.TResourceFor(tag, res.ResourceTranslation(), k.Path), }) k = types.LocaleKeyNamespaceDescription @@ -169,7 +169,7 @@ func (svc resourceTranslation) Namespace(ctx context.Context, ID uint64) (locale Resource: res.ResourceTranslation(), Lang: tag.String(), Key: k.Path, - Msg: svc.locale.TRFor(tag, res.ResourceTranslation(), k.Path), + Msg: svc.locale.TResourceFor(tag, res.ResourceTranslation(), k.Path), }) } @@ -195,7 +195,7 @@ func (svc resourceTranslation) Page(ctx context.Context, namespaceID uint64, ID Resource: res.ResourceTranslation(), Lang: tag.String(), Key: k.Path, - Msg: svc.locale.TRFor(tag, res.ResourceTranslation(), k.Path), + Msg: svc.locale.TResourceFor(tag, res.ResourceTranslation(), k.Path), }) k = types.LocaleKeyPageDescription @@ -203,7 +203,7 @@ func (svc resourceTranslation) Page(ctx context.Context, namespaceID uint64, ID Resource: res.ResourceTranslation(), Lang: tag.String(), Key: k.Path, - Msg: svc.locale.TRFor(tag, res.ResourceTranslation(), k.Path), + Msg: svc.locale.TResourceFor(tag, res.ResourceTranslation(), k.Path), }) } diff --git a/compose/service/locale.go b/compose/service/locale.go index b2c7f67a6..39d92a42d 100644 --- a/compose/service/locale.go +++ b/compose/service/locale.go @@ -24,7 +24,7 @@ func (svc resourceTranslation) moduleExtended(ctx context.Context, res *types.Mo Resource: f.ResourceTranslation(), Lang: tag.String(), Key: k.Path, - Msg: svc.locale.TRFor(tag, f.ResourceTranslation(), k.Path), + Msg: svc.locale.TResourceFor(tag, f.ResourceTranslation(), k.Path), }) // Extra field bits @@ -53,7 +53,7 @@ func (svc resourceTranslation) moduleFieldValidatorErrorHandler(ctx context.Cont Resource: f.ResourceTranslation(), Lang: tag.String(), Key: tKey, - Msg: svc.locale.TRFor(tag, f.ResourceTranslation(), tKey), + Msg: svc.locale.TResourceFor(tag, f.ResourceTranslation(), tKey), }) } @@ -78,7 +78,7 @@ func (svc resourceTranslation) pageExtended(ctx context.Context, res *types.Page Resource: res.ResourceTranslation(), Lang: tag.String(), Key: rpl.Replace(k.Path), - Msg: svc.locale.TRFor(tag, res.ResourceTranslation(), rpl.Replace(k.Path)), + Msg: svc.locale.TResourceFor(tag, res.ResourceTranslation(), rpl.Replace(k.Path)), }) k = types.LocaleKeyPageBlockDescription @@ -86,7 +86,7 @@ func (svc resourceTranslation) pageExtended(ctx context.Context, res *types.Page Resource: res.ResourceTranslation(), Lang: tag.String(), Key: rpl.Replace(k.Path), - Msg: svc.locale.TRFor(tag, res.ResourceTranslation(), rpl.Replace(k.Path)), + Msg: svc.locale.TResourceFor(tag, res.ResourceTranslation(), rpl.Replace(k.Path)), }) switch block.Kind { @@ -127,7 +127,7 @@ func (svc resourceTranslation) pageExtendedAutomatinBlock(tag language.Tag, res Resource: res.ResourceTranslation(), Lang: tag.String(), Key: rpl.Replace(k.Path), - Msg: svc.locale.TRFor(tag, res.ResourceTranslation(), rpl.Replace(k.Path)), + Msg: svc.locale.TResourceFor(tag, res.ResourceTranslation(), rpl.Replace(k.Path)), }) } diff --git a/pkg/codegen-v3/assets/templates/gocode/locale/service.go.tpl b/pkg/codegen-v3/assets/templates/gocode/locale/service.go.tpl index 5f3c3a6d5..9200440ea 100644 --- a/pkg/codegen-v3/assets/templates/gocode/locale/service.go.tpl +++ b/pkg/codegen-v3/assets/templates/gocode/locale/service.go.tpl @@ -123,7 +123,7 @@ func (svc resourceTranslation) {{ .Resource }}(ctx context.Context, {{ if .Local Resource: res.ResourceTranslation(), Lang: tag.String(), Key: k.Path, - Msg: svc.locale.TRFor(tag, res.ResourceTranslation(), k.Path), + Msg: svc.locale.TResourceFor(tag, res.ResourceTranslation(), k.Path), }) {{ end }} {{- end}} 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 48563f920..e4a41fd40 100644 --- a/pkg/codegen-v3/assets/templates/gocode/locale/types.go.tpl +++ b/pkg/codegen-v3/assets/templates/gocode/locale/types.go.tpl @@ -65,7 +65,7 @@ func {{ .Resource }}ResourceTranslation({{ if .Locale.Resource }}{{ range .Local cpts = append(cpts, {{range .Locale.Resource.References -}} strconv.FormatUint({{ unexport .Field }}, 10), {{- end }}) - + return fmt.Sprintf({{ .Resource }}ResourceTranslationTpl(), cpts...) {{- end }} } diff --git a/pkg/locale/locale.go b/pkg/locale/locale.go index cea3f6054..f0de41d04 100644 --- a/pkg/locale/locale.go +++ b/pkg/locale/locale.go @@ -81,8 +81,8 @@ func (l *Language) t(ns, key string, rr ...string) string { return key } -// tr returns the translated string for resource translations -func (l *Language) tr(ns, key string, rr ...string) string { +// tResource returns the translated string for resource translations +func (l *Language) tResource(ns, key string, rr ...string) string { l.l.RLock() defer l.l.RUnlock() @@ -96,10 +96,10 @@ func (l *Language) tr(ns, key string, rr ...string) string { } if l.extends != nil { - return l.extends.tr(ns, key, rr...) + return l.extends.tResource(ns, key, rr...) } - return key + return "" } // resourceTranslations returns all resource translations for the specified resource diff --git a/pkg/locale/service.go b/pkg/locale/service.go index 2daf7ea82..c143875e6 100644 --- a/pkg/locale/service.go +++ b/pkg/locale/service.go @@ -27,8 +27,8 @@ type ( } Resource interface { - TR(ctx context.Context, ns, key string, rr ...string) string - TRFor(tag language.Tag, ns, key string, rr ...string) string + TResource(ctx context.Context, ns, key string, rr ...string) string + TResourceFor(tag language.Tag, ns, key string, rr ...string) string Tags() []language.Tag ResourceTranslations(code language.Tag, resource string) ResourceTranslationIndex } @@ -387,18 +387,18 @@ func (svc *service) TFor(tag language.Tag, ns, key string, rr ...string) string return svc.t(tag, ns, key, rr...) } -// TR returns translated key for resource using list of replacement pairs +// TResource returns translated key for resource using list of replacement pairs // // Language is picked from the context -func (svc *service) TR(ctx context.Context, ns, key string, rr ...string) string { - return svc.tr(GetLanguageFromContext(ctx), ns, key, rr...) +func (svc *service) TResource(ctx context.Context, ns, key string, rr ...string) string { + return svc.tResource(GetLanguageFromContext(ctx), ns, key, rr...) } -// TRFor returns translated key for resource using list of replacement pairs +// TResourceFor returns translated key for resource using list of replacement pairs // // Language is picked from the context -func (svc *service) TRFor(tag language.Tag, ns, key string, rr ...string) string { - return svc.tr(tag, ns, key, rr...) +func (svc *service) TResourceFor(tag language.Tag, ns, key string, rr ...string) string { + return svc.tResource(tag, ns, key, rr...) } // ResourceTranslations returns all translations for the given language for the @@ -429,10 +429,10 @@ func (svc *service) t(code language.Tag, ns, key string, rr ...string) string { } // Finds language and uses it to translate the given key for resource -func (svc *service) tr(code language.Tag, ns, key string, rr ...string) string { +func (svc *service) tResource(code language.Tag, ns, key string, rr ...string) string { if svc != nil && svc.set != nil { if l, has := svc.set[code]; has { - return l.tr(ns, key, rr...) + return l.tResource(ns, key, rr...) } }