From 46f8ef9ed35a89c4cb8370ddd3c91a7ab2ef05b7 Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Sun, 3 Feb 2019 20:21:07 +1000 Subject: [PATCH] Be less strict with our language file loading, and handle multiple credits better --- irc/config.go | 54 +++++++++++++++++++++++-------------------------- irc/handlers.go | 2 +- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/irc/config.go b/irc/config.go index c19bf157..d4c71d6c 100644 --- a/irc/config.go +++ b/irc/config.go @@ -627,7 +627,7 @@ func LoadConfig(filename string) (config *Config, err error) { 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() lowerName := strings.ToLower(name) if !strings.HasSuffix(lowerName, ".lang.yaml") { @@ -658,42 +658,38 @@ func LoadConfig(filename string) (config *Config, err error) { ircName := strings.TrimSuffix(name, ".lang.yaml") + "-irc.lang.json" data, err = ioutil.ReadFile(filepath.Join(config.Languages.Path, ircName)) - if err != nil { - return nil, fmt.Errorf("Could not load language's irc file [%s]: %s", ircName, err.Error()) - } - - err = json.Unmarshal(data, &tlList) - if err != nil { - return nil, fmt.Errorf("Could not parse language's irc file [%s]: %s", ircName, err.Error()) - } - - for key, value := range tlList { - // because of how crowdin works, this is how we skip untranslated lines - if key == value || value == "" { - continue + if err == nil { + err = json.Unmarshal(data, &tlList) + if err != nil { + return nil, fmt.Errorf("Could not parse language's irc file [%s]: %s", ircName, err.Error()) + } + + for key, value := range tlList { + // because of how crowdin works, this is how we skip untranslated lines + if key == value || value == "" { + continue + } + langInfo.Translations[key] = value } - langInfo.Translations[key] = value } // load help strings file helpName := strings.TrimSuffix(name, ".lang.yaml") + "-help.lang.json" data, err = ioutil.ReadFile(filepath.Join(config.Languages.Path, helpName)) - if err != nil { - return nil, fmt.Errorf("Could not load language's help file [%s]: %s", helpName, err.Error()) - } - - err = json.Unmarshal(data, &tlList) - if err != nil { - return nil, fmt.Errorf("Could not parse language's help file [%s]: %s", helpName, err.Error()) - } - - for key, value := range tlList { - // because of how crowdin works, this is how we skip untranslated lines - if key == value || value == "" { - continue + if err == nil { + err = json.Unmarshal(data, &tlList) + if err != nil { + return nil, fmt.Errorf("Could not parse language's help file [%s]: %s", helpName, err.Error()) + } + + for key, value := range tlList { + // because of how crowdin works, this is how we skip untranslated lines + if key == value || value == "" { + continue + } + langInfo.Translations[key] = value } - langInfo.Translations[key] = value } // confirm that values are correct diff --git a/irc/handlers.go b/irc/handlers.go index 7fadeffa..5deac6b5 100644 --- a/irc/handlers.go +++ b/irc/handlers.go @@ -806,7 +806,7 @@ func infoHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Resp if 0 < len(tlines) { rb.Add(nil, server.name, RPL_INFO, client.nick, client.t("Translators:")) 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, "") }