main.go 545 B

12345678910111213141516171819202122232425262728
  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 main() {
  14. pwd, err := os.Getwd()
  15. if err != nil {
  16. log.Fatalf("failed getting working directory: %v", err)
  17. }
  18. td := filepath.Join(pwd, TranslationsDir)
  19. if _, err := os.Stat(td); err != nil {
  20. log.Fatalf("cannot access translations directory %s: %V", td, err)
  21. }
  22. gotext.Configure(td, "fr_FR", "demo")
  23. fmt.Println(gotext.GetD(Domain, "The weather is balmy"))
  24. }