Rename TR* to TResource* for clarity
This commit is contained in:
@@ -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