Some checks failed
continuous-integration/drone/push Build is failing
See #483
32 lines
497 B
Go
32 lines
497 B
Go
package lang
|
|
|
|
import (
|
|
"embed"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/leonelquinteros/gotext"
|
|
)
|
|
|
|
//go:embed locales
|
|
var assetFS embed.FS
|
|
|
|
func GetLocale() string {
|
|
return os.Getenv("LANG")
|
|
}
|
|
|
|
func LoadLocale(locale string) error {
|
|
localePath := fmt.Sprintf("locales/%s/%s.po", locale)
|
|
|
|
b, err := assetFS.ReadFile(localePath)
|
|
if err != nil {
|
|
return fmt.Errorf("unable to load %s: %s", localePath, err)
|
|
}
|
|
|
|
po := gotext.NewPo()
|
|
po.Parse(b)
|
|
gotext.GetStorage().AddTranslator("abra", po)
|
|
|
|
return nil
|
|
}
|