Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
93 lines
1.7 KiB
Go
93 lines
1.7 KiB
Go
package resource
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/cortezaproject/corteza/server/system/types"
|
|
"golang.org/x/text/language"
|
|
)
|
|
|
|
type (
|
|
ResourceTranslation struct {
|
|
*base
|
|
Res types.ResourceTranslationSet
|
|
|
|
RefResource string
|
|
RefRes *Ref
|
|
RefPath []*Ref
|
|
|
|
Priority int
|
|
}
|
|
)
|
|
|
|
var (
|
|
defaultLanguage = language.English
|
|
)
|
|
|
|
func NewResourceTranslation(res types.ResourceTranslationSet, refResource string, refRes *Ref, refPath ...*Ref) *ResourceTranslation {
|
|
r := &ResourceTranslation{base: &base{}}
|
|
r.SetResourceType(ResourceTranslationType)
|
|
r.Res = res
|
|
|
|
r.RefResource = refResource
|
|
r.RefRes = r.addRef(refRes)
|
|
|
|
// any additional constraints
|
|
for i, rp := range refPath {
|
|
ref := MakeRef(rp.ResourceType, rp.Identifiers)
|
|
|
|
r.RefRes.Constraint(ref)
|
|
if i > 0 {
|
|
for j := i - 1; j < i; j++ {
|
|
aux := refPath[j]
|
|
ref = ref.Constraint(MakeRef(aux.ResourceType, aux.Identifiers))
|
|
}
|
|
}
|
|
|
|
r.RefPath = append(r.RefPath, r.addRef(ref))
|
|
}
|
|
|
|
return r
|
|
}
|
|
|
|
func (r *ResourceTranslation) Resource() interface{} {
|
|
return r.Res
|
|
}
|
|
|
|
func (r *ResourceTranslation) ReRef(old RefSet, new RefSet) {
|
|
r.base.ReRef(old, new)
|
|
|
|
for i, o := range old {
|
|
if o.equals(r.RefRes) {
|
|
r.RefRes = new[i]
|
|
break
|
|
}
|
|
}
|
|
|
|
for i, o := range old {
|
|
if RefSet(r.RefPath).findRef(o) > -1 {
|
|
r.RefPath = RefSet(r.RefPath).replaceRef(o, new[i])
|
|
}
|
|
}
|
|
}
|
|
|
|
func (l *ResourceTranslation) MarkDefault() {
|
|
l.Priority = 1
|
|
}
|
|
|
|
func (l *ResourceTranslation) IsDefault() bool {
|
|
return l.Priority == 1
|
|
}
|
|
|
|
func (l *ResourceTranslation) MarkGeneric() {
|
|
l.Priority = 0
|
|
}
|
|
|
|
func (l *ResourceTranslation) IsGeneric() bool {
|
|
return l.Priority == 0
|
|
}
|
|
|
|
func ResourceTranslationErrNotFound(ii Identifiers) error {
|
|
return fmt.Errorf("resource translation not found %v", ii.StringSlice())
|
|
}
|