50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
|
package main
|
|||
|
|
|||
|
import (
|
|||
|
"github.com/cloudfoundry-attic/jibber_jabber"
|
|||
|
"golang.org/x/text/language"
|
|||
|
)
|
|||
|
|
|||
|
var locales = map[string]map[string]string{
|
|||
|
"zh-Hans": {
|
|||
|
"About": "关于",
|
|||
|
"Application": "应用",
|
|||
|
"Awaiting user input": "等待用户输入",
|
|||
|
"Destination folder": "目标文件夹",
|
|||
|
"Download": "下载",
|
|||
|
"Download playlists": "下载完整播单",
|
|||
|
"Download started": "下载已开始",
|
|||
|
"On network errors, e.g. HTTP 403, please retry a few times.": "如遇HTTP 403等网络错误,请重试几次。",
|
|||
|
"Pick another folder": "选择文件夹",
|
|||
|
"Video URL": "视频链接",
|
|||
|
},
|
|||
|
}
|
|||
|
var locale map[string]string
|
|||
|
|
|||
|
// Poor man's gettext.
|
|||
|
func tr(s string) string {
|
|||
|
t, ok := locale[s]
|
|||
|
if ok {
|
|||
|
return t
|
|||
|
}
|
|||
|
return s
|
|||
|
}
|
|||
|
|
|||
|
func initLanguages() {
|
|||
|
|
|||
|
userLang, err := jibber_jabber.DetectIETF()
|
|||
|
if err != nil {
|
|||
|
userLang = "en"
|
|||
|
}
|
|||
|
availableLangs := []string{"en"}
|
|||
|
availableTags := []language.Tag{language.English}
|
|||
|
for l := range locales {
|
|||
|
availableLangs = append(availableLangs, l)
|
|||
|
availableTags = append(availableTags, language.Make(l))
|
|||
|
}
|
|||
|
matcher := language.NewMatcher(availableTags)
|
|||
|
_, index, _ := matcher.Match(language.Make(userLang))
|
|||
|
locale = locales[availableLangs[index]]
|
|||
|
|
|||
|
}
|