package localization import ( "crypto/sha256" "encoding/hex" "slices" "strconv" "strings" ) func Revision(rows []Row) string { ordered := slices.Clone(rows) slices.SortFunc(ordered, func(left Row, right Row) int { return strings.Compare(left.Tag, right.Tag) }) digest := sha256.New() for _, row := range ordered { digest.Write([]byte(row.Tag + "|" + strconv.FormatBool(row.IsDefault) + "|" + strconv.FormatBool(row.Enabled) + "|" + socialText(row.SocialLocale) + "\n")) } return hex.EncodeToString(digest.Sum(nil)) } func SameRows(left []Row, right []Row) bool { return Revision(left) == Revision(right) } func (r Row) Equal(other Row) bool { return r.Tag == other.Tag && r.IsDefault == other.IsDefault && r.Enabled == other.Enabled && r.Confirmed == other.Confirmed && sameSocialLocale(r.SocialLocale, other.SocialLocale) } func sameSocialLocale(left *string, right *string) bool { if left == nil || right == nil { return left == right } return *left == *right } func socialText(social *string) string { if social == nil { return "" } return *social }