1
0
Fork 0
mirror of https://github.com/Luzifer/sii.git synced 2024-12-21 00:21:15 +00:00
sii/block_localization_db.go

42 lines
716 B
Go
Raw Normal View History

package sii
import "strings"
func init() {
RegisterBlock(&LocalizationDB{})
}
type LocalizationDB struct {
Keys []string `sii:"key"`
Vals []string `sii:"val"`
blockName string
}
func (LocalizationDB) Class() string { return "localization_db" }
func (l *LocalizationDB) Init(class, name string) {
l.blockName = name
}
func (l LocalizationDB) Name() string { return l.blockName }
func (l LocalizationDB) GetTranslation(key string) string {
key = strings.Trim(key, "@")
for i, k := range l.Keys {
if k == key {
val := l.Vals[i]
if strings.HasPrefix(val, "@@") {
// Some translations are translation keys themselves
return l.GetTranslation(val)
}
return val
}
}
return key
}