forked from ublue-os/fleek
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fleek.go
50 lines (43 loc) · 742 Bytes
/
fleek.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package fleek
import (
"embed"
"os"
"github.com/fitv/go-i18n"
)
//go:embed locales/*.yml
var fs embed.FS
func NewApp() *App {
i18n, err := i18n.New(fs, "locales")
if err != nil {
panic(err)
}
i18n.SetDefaultLocale("en")
preferred := locale()
available, err := fs.ReadDir("locales")
if err != nil {
panic(err)
}
for _, f := range available {
if f.Name() == preferred+".yml" {
i18n.SetDefaultLocale(preferred)
break
}
}
return &App{
I18n: i18n,
}
}
type App struct {
*i18n.I18n
}
// locale returns the two digit locale code
// from the LANG environment variable, or "en"
// if unset.
func locale() string {
lang := os.Getenv("LANG")
if lang == "" {
lang = "en"
}
locale := lang[:2]
return locale
}