Add back-end support for boolean label res. translations
This commit is contained in:
parent
a1a462c5fb
commit
c0200345ac
@ -46,6 +46,10 @@ moduleField: schema.#resource & {
|
||||
path: ["meta", "options", {part: "value", var: true}, "text"]
|
||||
customHandler: true
|
||||
}
|
||||
optionsBoolLabels: {
|
||||
path: ["meta", "bool", {part: "value", var: true}, "label"]
|
||||
customHandler: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,6 +71,12 @@ func (svc resourceTranslationsManager) moduleExtended(ctx context.Context, res *
|
||||
return nil, err
|
||||
}
|
||||
out = append(out, set...)
|
||||
|
||||
set, err = svc.moduleFieldBoolHandler(ctx, tag, f)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out = append(out, set...)
|
||||
}
|
||||
}
|
||||
|
||||
@ -141,6 +147,32 @@ func (svc resourceTranslationsManager) moduleFieldOptionsHandler(ctx context.Con
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (svc resourceTranslationsManager) moduleFieldBoolHandler(ctx context.Context, tag language.Tag, f *types.ModuleField) (locale.ResourceTranslationSet, error) {
|
||||
if f.Kind != "Bool" {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
out := make(locale.ResourceTranslationSet, 0, 2)
|
||||
|
||||
trKey := strings.NewReplacer("{{value}}", "true").Replace(types.LocaleKeyModuleFieldMetaBoolValueLabel.Path)
|
||||
out = append(out, &locale.ResourceTranslation{
|
||||
Resource: f.ResourceTranslation(),
|
||||
Lang: tag.String(),
|
||||
Key: trKey,
|
||||
Msg: svc.locale.TResourceFor(tag, f.ResourceTranslation(), trKey),
|
||||
})
|
||||
|
||||
trKey = strings.NewReplacer("{{value}}", "false").Replace(types.LocaleKeyModuleFieldMetaBoolValueLabel.Path)
|
||||
out = append(out, &locale.ResourceTranslation{
|
||||
Resource: f.ResourceTranslation(),
|
||||
Lang: tag.String(),
|
||||
Key: trKey,
|
||||
Msg: svc.locale.TResourceFor(tag, f.ResourceTranslation(), trKey),
|
||||
})
|
||||
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (svc resourceTranslationsManager) pageExtended(ctx context.Context, res *types.Page) (out locale.ResourceTranslationSet, err error) {
|
||||
var (
|
||||
k types.LocaleKey
|
||||
|
||||
5
compose/types/locale.gen.go
generated
5
compose/types/locale.gen.go
generated
@ -39,6 +39,7 @@ var (
|
||||
LocaleKeyModuleFieldMetaHintEdit = LocaleKey{Path: "meta.hint.edit"}
|
||||
LocaleKeyModuleFieldExpressionValidatorValidatorIDError = LocaleKey{Path: "expression.validator.{{validatorID}}.error"}
|
||||
LocaleKeyModuleFieldMetaOptionsValueText = LocaleKey{Path: "meta.options.{{value}}.text"}
|
||||
LocaleKeyModuleFieldMetaBoolValueLabel = LocaleKey{Path: "meta.bool.{{value}}.label"}
|
||||
LocaleKeyNamespaceName = LocaleKey{Path: "name"}
|
||||
LocaleKeyNamespaceMetaSubtitle = LocaleKey{Path: "meta.subtitle"}
|
||||
LocaleKeyNamespaceMetaDescription = LocaleKey{Path: "meta.description"}
|
||||
@ -148,6 +149,8 @@ func (r *ModuleField) DecodeTranslations(tt locale.ResourceTranslationIndex) {
|
||||
|
||||
r.decodeTranslationsMetaOptionsValueText(tt)
|
||||
|
||||
r.decodeTranslationsMetaBoolValueLabel(tt)
|
||||
|
||||
}
|
||||
|
||||
func (r *ModuleField) EncodeTranslations() (out locale.ResourceTranslationSet) {
|
||||
@ -171,6 +174,8 @@ func (r *ModuleField) EncodeTranslations() (out locale.ResourceTranslationSet) {
|
||||
|
||||
out = append(out, r.encodeTranslationsMetaOptionsValueText()...)
|
||||
|
||||
out = append(out, r.encodeTranslationsMetaBoolValueLabel()...)
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
|
||||
@ -155,6 +155,21 @@ func (f *ModuleField) decodeTranslationsMetaOptionsValueText(tt locale.ResourceT
|
||||
}
|
||||
}
|
||||
|
||||
// Decodes translations and modifies options
|
||||
func (f *ModuleField) decodeTranslationsMetaBoolValueLabel(tt locale.ResourceTranslationIndex) {
|
||||
if f.Kind != "Bool" {
|
||||
return
|
||||
}
|
||||
|
||||
var aux *locale.ResourceTranslation
|
||||
if aux = tt.FindByKey(strings.NewReplacer("{{value}}", "true").Replace(LocaleKeyModuleFieldMetaBoolValueLabel.Path)); aux != nil {
|
||||
f.setOptionKey(aux.Msg, "trueLabel")
|
||||
}
|
||||
if aux = tt.FindByKey(strings.NewReplacer("{{value}}", "false").Replace(LocaleKeyModuleFieldMetaBoolValueLabel.Path)); aux != nil {
|
||||
f.setOptionKey(aux.Msg, "falseLabel")
|
||||
}
|
||||
}
|
||||
|
||||
func (m *ModuleField) encodeTranslationsExpressionValidatorValidatorIDError() (out locale.ResourceTranslationSet) {
|
||||
out = make(locale.ResourceTranslationSet, 0, 3)
|
||||
|
||||
@ -261,6 +276,27 @@ func (f *ModuleField) encodeTranslationsMetaOptionsValueText() (out locale.Resou
|
||||
return
|
||||
}
|
||||
|
||||
func (m *ModuleField) encodeTranslationsMetaBoolValueLabel() (out locale.ResourceTranslationSet) {
|
||||
if m.Kind != "Bool" {
|
||||
return
|
||||
}
|
||||
|
||||
out = make(locale.ResourceTranslationSet, 0, 3)
|
||||
out = append(out, &locale.ResourceTranslation{
|
||||
Resource: m.ResourceTranslation(),
|
||||
Key: strings.NewReplacer("{{value}}", "true").Replace(LocaleKeyModuleFieldMetaBoolValueLabel.Path),
|
||||
Msg: m.Options.String("trueLabel"),
|
||||
})
|
||||
|
||||
out = append(out, &locale.ResourceTranslation{
|
||||
Resource: m.ResourceTranslation(),
|
||||
Key: strings.NewReplacer("{{value}}", "false").Replace(LocaleKeyModuleFieldMetaBoolValueLabel.Path),
|
||||
Msg: m.Options.String("falseLabel"),
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (f ModuleField) Clone() *ModuleField {
|
||||
return &f
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user