Do not translate legal to the default language

It is already in the “default relations”, and there is no need to repeat
them.
This commit is contained in:
jordi fita mas 2024-01-12 19:57:11 +01:00
parent 2b702d6632
commit 734178657d
1 changed files with 15 additions and 12 deletions

View File

@ -138,13 +138,21 @@ func addLegal(w http.ResponseWriter, r *http.Request, user *auth.User, company *
if err != nil { if err != nil {
return err return err
} }
return translateLegal(ctx, tx, company, f)
})
}
func translateLegal(ctx context.Context, tx *database.Tx, company *auth.Company, f *legalForm) error {
for lang := range company.Locales { for lang := range company.Locales {
if err := tx.TranslateLegalText(ctx, company.ID, f.Slug.Val, lang, f.Name[lang.String()].Val, f.Content[lang.String()].Val); err != nil { l := lang.String()
if l == f.DefaultLang {
continue
}
if err := tx.TranslateLegalText(ctx, company.ID, f.Slug.Val, lang, f.Name[l].Val, f.Content[l].Val); err != nil {
return err return err
} }
} }
return nil return nil
})
} }
func editLegal(w http.ResponseWriter, r *http.Request, user *auth.User, company *auth.Company, conn *database.Conn, f *legalForm) { func editLegal(w http.ResponseWriter, r *http.Request, user *auth.User, company *auth.Company, conn *database.Conn, f *legalForm) {
@ -159,12 +167,7 @@ func editLegal(w http.ResponseWriter, r *http.Request, user *auth.User, company
if err != nil { if err != nil {
return err return err
} }
for lang := range company.Locales { return translateLegal(ctx, tx, company, f)
if err := tx.TranslateLegalText(ctx, company.ID, f.Slug.Val, lang, f.Name[lang.String()].Val, f.Content[lang.String()].Val); err != nil {
return err
}
}
return nil
}) })
} }