3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 18:52:41 +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: "*", nickCasefolded: "*",
nickMaskString: "*", // * is used until actual nick is given nickMaskString: "*", // * is used until actual nick is given
} }
client.languages = server.languages.Default()
client.recomputeMaxlens() client.recomputeMaxlens()
if isTLS { if isTLS {

View File

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

View File

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