01basic.go 840 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package main
  2. import (
  3. "log"
  4. "golang.org/x/text/language"
  5. "golang.org/x/text/message"
  6. )
  7. const (
  8. Flowers = "There are %v flowers in our garden.\n"
  9. )
  10. func init() {
  11. message.SetString(language.French, Flowers, "Il y a %d fleurs dans notre jardin.\n")
  12. message.SetString(language.German, Flowers, "In unserem Garten stehen %d Blumen.\n")
  13. }
  14. func main() {
  15. frFR, err := language.Parse("fr_FR") // Also: ParseBase, ParseRegion, Composer
  16. if err != nil {
  17. log.Fatalf("parsing fr_FR: %v", err)
  18. }
  19. deDE, err := language.Parse("de_DE") // Also: ParseBase, ParseRegion, Composer
  20. if err != nil {
  21. log.Fatalf("parsing de_DE: %v", err)
  22. }
  23. pUK := message.NewPrinter(language.BritishEnglish)
  24. dFR := message.NewPrinter(deDE)
  25. pFR := message.NewPrinter(frFR)
  26. pUK.Printf(Flowers, 1500)
  27. pFR.Printf(Flowers, 1500)
  28. dFR.Printf(Flowers, 1500)
  29. }