-
Notifications
You must be signed in to change notification settings - Fork 1
/
localizer.go
70 lines (57 loc) · 1.47 KB
/
localizer.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import "github.com/ketMix/retromancer/resources"
type Localizer struct {
resources *ResourceManager
locale string
currentLocale *resources.Locale
backupLocale *resources.Locale
GPT *resources.GPT
gptActive bool
}
func (l *Localizer) SetGPTStyle(style string) {
l.GPT.Style = style
}
func (l *Localizer) GetGPTStyle() string {
return l.GPT.Style
}
func (l *Localizer) SetGPTKey(key string) {
l.GPT.SetKey(key)
}
func (l *Localizer) GetGPTKey() string {
return l.GPT.GetKey()
}
func (l *Localizer) CheckGPTKey() bool {
return l.GPT.CheckKey()
}
func (l *Localizer) GPTIsActive() bool {
return l.gptActive
}
func (l *Localizer) InitGPT() {
l.GPT = resources.InitGPT(l.resources.files)
}
func (l *Localizer) Locale() string {
return l.locale
}
func (l *Localizer) SetLocale(loc string, gpt bool) {
l.locale = loc
l.backupLocale = l.resources.GetAs("locales", "en", (*resources.Locale)(nil)).(*resources.Locale)
if !gpt {
l.currentLocale = l.resources.GetAs("locales", loc, (*resources.Locale)(nil)).(*resources.Locale)
return
}
currentLocale, err := l.GPT.GetLocale(l.backupLocale, loc)
if err != nil {
l.currentLocale = l.resources.GetAs("locales", loc, (*resources.Locale)(nil)).(*resources.Locale)
l.gptActive = false
} else {
l.currentLocale = currentLocale
l.gptActive = true
}
}
func (l *Localizer) Get(key string) string {
s := l.currentLocale.Get(key)
if s == key {
return l.backupLocale.Get(key)
}
return s
}