package settings

import "strings"

var validUILocales = map[string]bool{
	"zh-CN": true,
	"zh-TW": true,
	"en":    true,
}

func NormalizeUILocale(v string) string {
	v = strings.TrimSpace(v)
	if validUILocales[v] {
		return v
	}
	return "zh-CN"
}

func applyLocaleDisplayDefaults(out map[string]string) {
	if strings.TrimSpace(out[KeyUILocale]) == "" {
		out[KeyUILocale] = "zh-CN"
	}
}

func normalizeLocaleSubmit(req map[string]string) {
	if v, ok := req[KeyUILocale]; ok {
		req[KeyUILocale] = NormalizeUILocale(v)
	}
}
