3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-23 11:12:44 +01:00

Be less strict with our language file loading, and handle multiple credits better

This commit is contained in:
Daniel Oaks 2019-02-03 20:21:07 +10:00
parent bcb8a6fe7e
commit 46f8ef9ed3
2 changed files with 26 additions and 30 deletions

View File

@ -627,7 +627,7 @@ func LoadConfig(filename string) (config *Config, err error) {
continue continue
} }
// only load core .lang.yaml files, and ignore help/irc files // only load core .lang.yaml file, and ignore help/irc files
name := f.Name() name := f.Name()
lowerName := strings.ToLower(name) lowerName := strings.ToLower(name)
if !strings.HasSuffix(lowerName, ".lang.yaml") { if !strings.HasSuffix(lowerName, ".lang.yaml") {
@ -658,10 +658,7 @@ func LoadConfig(filename string) (config *Config, err error) {
ircName := strings.TrimSuffix(name, ".lang.yaml") + "-irc.lang.json" ircName := strings.TrimSuffix(name, ".lang.yaml") + "-irc.lang.json"
data, err = ioutil.ReadFile(filepath.Join(config.Languages.Path, ircName)) data, err = ioutil.ReadFile(filepath.Join(config.Languages.Path, ircName))
if err != nil { if err == nil {
return nil, fmt.Errorf("Could not load language's irc file [%s]: %s", ircName, err.Error())
}
err = json.Unmarshal(data, &tlList) err = json.Unmarshal(data, &tlList)
if err != nil { if err != nil {
return nil, fmt.Errorf("Could not parse language's irc file [%s]: %s", ircName, err.Error()) return nil, fmt.Errorf("Could not parse language's irc file [%s]: %s", ircName, err.Error())
@ -674,15 +671,13 @@ func LoadConfig(filename string) (config *Config, err error) {
} }
langInfo.Translations[key] = value langInfo.Translations[key] = value
} }
}
// load help strings file // load help strings file
helpName := strings.TrimSuffix(name, ".lang.yaml") + "-help.lang.json" helpName := strings.TrimSuffix(name, ".lang.yaml") + "-help.lang.json"
data, err = ioutil.ReadFile(filepath.Join(config.Languages.Path, helpName)) data, err = ioutil.ReadFile(filepath.Join(config.Languages.Path, helpName))
if err != nil { if err == nil {
return nil, fmt.Errorf("Could not load language's help file [%s]: %s", helpName, err.Error())
}
err = json.Unmarshal(data, &tlList) err = json.Unmarshal(data, &tlList)
if err != nil { if err != nil {
return nil, fmt.Errorf("Could not parse language's help file [%s]: %s", helpName, err.Error()) return nil, fmt.Errorf("Could not parse language's help file [%s]: %s", helpName, err.Error())
@ -695,6 +690,7 @@ func LoadConfig(filename string) (config *Config, err error) {
} }
langInfo.Translations[key] = value langInfo.Translations[key] = value
} }
}
// confirm that values are correct // confirm that values are correct
if langInfo.Code == "en" { if langInfo.Code == "en" {

View File

@ -806,7 +806,7 @@ func infoHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Resp
if 0 < len(tlines) { if 0 < len(tlines) {
rb.Add(nil, server.name, RPL_INFO, client.nick, client.t("Translators:")) rb.Add(nil, server.name, RPL_INFO, client.nick, client.t("Translators:"))
for _, line := range tlines { for _, line := range tlines {
rb.Add(nil, server.name, RPL_INFO, client.nick, " "+line) rb.Add(nil, server.name, RPL_INFO, client.nick, " "+strings.Replace(line, "\n", ", ", -1))
} }
rb.Add(nil, server.name, RPL_INFO, client.nick, "") rb.Add(nil, server.name, RPL_INFO, client.nick, "")
} }