don't use bad locale
This commit is contained in:
parent
74ca4caca5
commit
e13dcf9e20
@ -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)
|
||||||
@ -43,7 +46,7 @@ func NewI18n(locale, dir string) (*I18N, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
found:= false
|
found := false
|
||||||
serverLangs := make([]language.Tag, 1)
|
serverLangs := make([]language.Tag, 1)
|
||||||
// serverLangs[0] = language.AmericanEnglish // en-US fallback
|
// serverLangs[0] = language.AmericanEnglish // en-US fallback
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user