l10n and bot command auto generation; v0.6.0
This commit is contained in:
27
l10n.go
Normal file
27
l10n.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package laniakea
|
||||
|
||||
// DictEntry {key:{ru:123,en:123}}
|
||||
type DictEntry map[string]string
|
||||
type L10n struct {
|
||||
entries map[string]DictEntry
|
||||
fallbackLang string
|
||||
}
|
||||
|
||||
func NewL10n(fallbackLanguage string) *L10n {
|
||||
return &L10n{make(map[string]DictEntry), fallbackLanguage}
|
||||
}
|
||||
func (l *L10n) AddDictEntry(key string, value DictEntry) *L10n {
|
||||
l.entries[key] = value
|
||||
return l
|
||||
}
|
||||
func (l *L10n) GetFallbackLanguage() string {
|
||||
return l.fallbackLang
|
||||
}
|
||||
|
||||
func (l *L10n) Translate(lang, key string) string {
|
||||
s, ok := l.entries[key]
|
||||
if !ok {
|
||||
return key
|
||||
}
|
||||
return s[lang]
|
||||
}
|
||||
Reference in New Issue
Block a user