Some checks failed
continuous-integration/drone/push Build is failing
See #483
35 lines
515 B
Go
35 lines
515 B
Go
package i18n
|
|
|
|
import (
|
|
"embed"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/leonelquinteros/gotext"
|
|
)
|
|
|
|
//go:embed locales
|
|
var assetFS embed.FS
|
|
|
|
func GetLocale() string {
|
|
return os.Getenv("LANG")
|
|
}
|
|
|
|
func LoadLocale() *gotext.Po {
|
|
locale := GetLocale()
|
|
|
|
localePath := fmt.Sprintf("locales/%s/LC_MESSAGES/default.po", locale)
|
|
|
|
b, err := assetFS.ReadFile(localePath)
|
|
if err != nil {
|
|
panic(fmt.Sprintf("i18n: unable to load %s: %s", localePath, err))
|
|
}
|
|
|
|
po := gotext.NewPo()
|
|
po.Parse(b)
|
|
|
|
return po
|
|
}
|
|
|
|
var G = LoadLocale().Get
|