Archived
1
0

don't use bad locale

This commit is contained in:
Jeff Becker 2019-02-13 08:34:54 -05:00
parent 74ca4caca5
commit e13dcf9e20
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

View File

@ -1,13 +1,13 @@
package srnd package srnd
import ( import (
"errors"
"github.com/majestrate/configparser" "github.com/majestrate/configparser"
"golang.org/x/text/language" "golang.org/x/text/language"
"io/ioutil" "io/ioutil"
"log" "log"
"path/filepath" "path/filepath"
"strings" "strings"
"errors"
) )
type I18N struct { type I18N struct {
@ -36,6 +36,9 @@ func InitI18n(locale, dir string) {
} }
func NewI18n(locale, dir string) (*I18N, error) { func NewI18n(locale, dir string) (*I18N, error) {
if locale == "und" {
locale = "en"
}
log.Println("get locale", locale) log.Println("get locale", locale)
pref := language.Make(locale) // falls back to en-US on parse error pref := language.Make(locale) // falls back to en-US on parse error
files, err := ioutil.ReadDir(dir) files, err := ioutil.ReadDir(dir)
@ -52,7 +55,7 @@ func NewI18n(locale, dir string) (*I18N, error) {
tag, err := language.Parse(name) tag, err := language.Parse(name)
if err == nil { if err == nil {
serverLangs = append(serverLangs, tag) serverLangs = append(serverLangs, tag)
found = true; found = true
} }
} }
} }