-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlocales.go
47 lines (39 loc) · 909 Bytes
/
locales.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"encoding/json"
"os"
)
// Localization holds the localized strings for different languages
type Localization struct {
Prompts map[string]string `json:"prompts"`
Responses map[string]string `json:"responses"`
}
var localizations map[string]Localization
func loadLocalizations() error {
data, err := os.ReadFile("localizations.json")
if err != nil {
return err
}
err = json.Unmarshal(data, &localizations)
if err != nil {
return err
}
return nil
}
func getLocalizedString(lang, key string, category string) string {
localization := localizations[config.Localization.DefaultLanguage]
if value, ok := localizations[lang]; ok {
localization = value
}
switch category {
case "prompt":
if value, ok := localization.Prompts[key]; ok {
return value
}
case "response":
if value, ok := localization.Responses[key]; ok {
return value
}
}
return ""
}