Rename TR* to TResource* for clarity
This commit is contained in:
Generated
+6
-6
@@ -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),
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -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)),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -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}}
|
||||
|
||||
@@ -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 }}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
+10
-10
@@ -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...)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user