3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 10:42:52 +01:00

Set default client language when creating them

This commit is contained in:
Daniel Oaks 2018-01-22 21:30:28 +10:00
parent 275227a461
commit 090095b2b9
3 changed files with 16 additions and 2 deletions

View File

@ -102,6 +102,7 @@ func NewClient(server *Server, conn net.Conn, isTLS bool) *Client {
nickCasefolded: "*",
nickMaskString: "*", // * is used until actual nick is given
}
client.languages = server.languages.Default()
client.recomputeMaxlens()
if isTLS {

View File

@ -13,13 +13,15 @@ type LanguageManager struct {
sync.RWMutex
Info map[string]LangData
translations map[string]map[string]string
defaultLang string
}
// NewLanguageManager returns a new LanguageManager.
func NewLanguageManager(languageData map[string]LangData) *LanguageManager {
func NewLanguageManager(defaultLang string, languageData map[string]LangData) *LanguageManager {
lm := LanguageManager{
Info: make(map[string]LangData),
translations: make(map[string]map[string]string),
defaultLang: defaultLang,
}
// make fake "en" info
@ -38,6 +40,17 @@ func NewLanguageManager(languageData map[string]LangData) *LanguageManager {
return &lm
}
// Default returns the default languages.
func (lm *LanguageManager) Default() []string {
lm.RLock()
defer lm.RUnlock()
if lm.defaultLang == "" {
return []string{}
}
return []string{lm.defaultLang}
}
// Count returns how many languages we have.
func (lm *LanguageManager) Count() int {
lm.RLock()

View File

@ -150,7 +150,7 @@ func NewServer(config *Config, logger *logger.Manager) (*Server, error) {
commands: make(chan Command),
connectionLimiter: connection_limits.NewLimiter(),
connectionThrottler: connection_limits.NewThrottler(),
languages: NewLanguageManager(config.Languages.Data),
languages: NewLanguageManager(config.Languages.Default, config.Languages.Data),
listeners: make(map[string]*ListenerWrapper),
logger: logger,
monitorManager: NewMonitorManager(),