O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

  1. Open the console and create the folder chapter03/recipe07.
  2. Navigate to the directory.
  3. Create the plurals.go file with the following content:
        package main        import (          "golang.org/x/text/feature/plural"          "golang.org/x/text/language"          "golang.org/x/text/message"        )        func main() {          message.Set(language.English, "%d items to do",            plural.Selectf(1, "%d", "=0", "no items to do",              plural.One, "one item to do",              "<100", "%[1]d items to do",              plural.Other, "lot of items to do",          ))          message.Set(language.English, "The average is %.2f",            plural.Selectf(1, "%.2f",              "<1", "The average is zero",              "=1", "The average is one",              plural.Other, "The average is %[1]f ",          ))          prt := message.NewPrinter(language.English)          prt.Printf("%d items to do", 0) prt.Println() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required