2026-04-02 03:49:25 +00:00
|
|
|
package i18n
|
|
|
|
|
|
|
|
|
|
import "dappco.re/go/core"
|
|
|
|
|
|
|
|
|
|
func mapValueString(values any, key string) (string, bool) {
|
|
|
|
|
switch m := values.(type) {
|
|
|
|
|
case map[string]any:
|
|
|
|
|
raw, ok := m[key]
|
|
|
|
|
if !ok {
|
|
|
|
|
return "", false
|
|
|
|
|
}
|
|
|
|
|
text := core.Trim(core.Sprintf("%v", raw))
|
|
|
|
|
if text == "" {
|
|
|
|
|
return "", false
|
|
|
|
|
}
|
|
|
|
|
return text, true
|
|
|
|
|
case map[string]string:
|
|
|
|
|
text, ok := m[key]
|
|
|
|
|
if !ok {
|
|
|
|
|
return "", false
|
|
|
|
|
}
|
|
|
|
|
text = core.Trim(text)
|
|
|
|
|
if text == "" {
|
|
|
|
|
return "", false
|
|
|
|
|
}
|
|
|
|
|
return text, true
|
|
|
|
|
default:
|
|
|
|
|
return "", false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func contextMapValues(values any) map[string]any {
|
|
|
|
|
switch m := values.(type) {
|
|
|
|
|
case map[string]any:
|
|
|
|
|
return contextMapValuesAny(m)
|
|
|
|
|
case map[string]string:
|
|
|
|
|
return contextMapValuesString(m)
|
|
|
|
|
default:
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func contextMapValuesAny(values map[string]any) map[string]any {
|
|
|
|
|
if len(values) == 0 {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
extra := make(map[string]any, len(values))
|
|
|
|
|
for key, value := range values {
|
|
|
|
|
switch key {
|
2026-04-02 07:59:58 +00:00
|
|
|
case "Context", "Gender", "Location", "Formality", "Count", "IsPlural":
|
2026-04-02 03:49:25 +00:00
|
|
|
continue
|
|
|
|
|
case "Extra", "extra", "Extras", "extras":
|
|
|
|
|
mergeContextExtra(extra, value)
|
|
|
|
|
continue
|
|
|
|
|
default:
|
|
|
|
|
extra[key] = value
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if len(extra) == 0 {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
return extra
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func contextMapValuesString(values map[string]string) map[string]any {
|
|
|
|
|
if len(values) == 0 {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
extra := make(map[string]any, len(values))
|
|
|
|
|
for key, value := range values {
|
|
|
|
|
switch key {
|
2026-04-02 07:59:58 +00:00
|
|
|
case "Context", "Gender", "Location", "Formality", "Count", "IsPlural",
|
|
|
|
|
"Extra", "extra", "Extras", "extras":
|
2026-04-02 03:49:25 +00:00
|
|
|
continue
|
|
|
|
|
default:
|
|
|
|
|
extra[key] = value
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if len(extra) == 0 {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
return extra
|
|
|
|
|
}
|