main.go 571 B

1234567891011121314151617181920212223242526272829303132
  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "os"
  6. "path/filepath"
  7. "github.com/leonelquinteros/gotext"
  8. )
  9. const (
  10. Domain = "demo"
  11. TranslationsDir = "../translations"
  12. )
  13. func init() {
  14. gotext.
  15. }
  16. func main() {
  17. pwd, err := os.Getwd()
  18. if err != nil {
  19. log.Fatalf("failed getting working directory: %v", err)
  20. }
  21. td := filepath.Join(pwd, TranslationsDir)
  22. if _, err := os.Stat(td); err != nil {
  23. log.Fatalf("cannot access translations directory %s: %V", td, err)
  24. }
  25. gotext.Configure(td, "fr_FR", "demo")
  26. fmt.Println(gotext.GetD(Domain, "The weather is balmy"))
  27. }