manpagez: man pages & more
info gettext
Home | html | info | man

File: gettext.info,  Node: Go,  Next: Ruby,  Prev: Rust,  Up: List of Programming Languages

16.5.13 Go
----------

   Three packages are available, that can be used for message
localization with PO files:
   • The ‘github.com/leonelquinteros/gotext’ package.

     Documentation:
     

     Source code: 
   • The ‘github.com/gosexy/gettext’ package.

     Documentation: 

     Source code: 
   • The ‘github.com/snapcore/go-gettext’ package.

     Documentation: 

     Source code: 

   Go programs can be classified as one of:
   • _Single-locale_ programs, that use the same locale across all
     threads of the program.  Example: Most command-line programs.
   • _Multi-locale_ programs, that use one locale per thread.  Example:
     Web servers.

   The three different packages support these two classes of programs
differently:
   • ‘github.com/leonelquinteros/gotext’ package: It has two different
     APIs, one for the single-locale case and one for the multi-locale
     case.
   • ‘github.com/gosexy/gettext’ package: Its API supports only the
     single-locale case.
   • ‘github.com/snapcore/go-gettext’ package: Its API supports the
     single-locale case and the multi-locale case in the same way.

Gettext support characteristics:
--------------------------------

RPMs
     golang

Ubuntu packages
     golang-go (which provides the ‘go’ program), or gccgo (which
     provides a ‘go-VERSION’ command).
     gccgo has better portability; for example it works on SPARC CPUs.

File extension
     ‘go’

String syntax
     ‘"abc"’, ‘`abc`’

gettext shorthand
     --

gettext/ngettext functions
     This depends on the API:
        • ‘github.com/leonelquinteros/gotext’ API: ‘Get’, ‘GetD’,
          ‘GetN’, ‘GetND’
        • ‘github.com/gosexy/gettext’ API: ‘Gettext’, ‘DGettext’,
          ‘DCGettext’, ‘NGettext’, ‘DNGettext’, ‘DCNGettext’
        • ‘github.com/snapcore/go-gettext’ API: ‘Gettext’, ‘NGettext’

     Note that the ‘ngettext’-like functions need to take two argument
     strings that consume the same number of arguments.  For example,
     you cannot write ‘fmt.Sprintf(gotext.GetN("a piece", "%d pieces",
     n), n)’ because in the singular case, ‘fmt.Sprintf’ would treat the
     unused argument as an error and produce ‘"a piece%!(EXTRA int=1)"’
     instead of the desired ‘"a piece"’.  As a workaround, you need to
     convert ‘n’ to a string and format that string with precision zero:
     ‘fmt.Sprintf(gotext.GetN("%.0sa piece", "%s pieces", n),
     strconv.Itoa(n))’

textdomain
     This depends on the API:
        • ‘github.com/leonelquinteros/gotext’ API: ‘Locale.AddDomain’
          method or ‘gotext.Configure’ function
        • ‘github.com/gosexy/gettext’ API: ‘Textdomain’ function
        • ‘github.com/snapcore/go-gettext’ API: ‘TextDomain’ constructor

bindtextdomain
     This depends on the API:
        • ‘github.com/leonelquinteros/gotext’ API: ‘gotext.NewLocale’
          function or ‘gotext.Configure’ function
        • ‘github.com/gosexy/gettext’ API: ‘BindTextdomain’ function
        • ‘github.com/snapcore/go-gettext’ API: ‘TextDomain’ constructor

setlocale
     This depends on the API:
        • ‘github.com/leonelquinteros/gotext’ API: Programmer must
          determine the appropriate locale and pass it to the
          ‘gotext.NewLocale’ function or ‘gotext.Configure’ function.
        • ‘github.com/gosexy/gettext’ API: Programmer must call
          ‘gettext.SetLocale(gettext.LcAll, "")’.
        • ‘github.com/snapcore/go-gettext’ API: Programmer must
          determine the appropriate locale and pass it to the
          ‘TextDomain.Locale’ method.

Prerequisite
     This depends on the API:
        • ‘github.com/leonelquinteros/gotext’ API: ‘import
          ("github.com/leonelquinteros/gotext")’
        • ‘github.com/gosexy/gettext’ API: ‘import
          ("github.com/gosexy/gettext")’
        • ‘github.com/snapcore/go-gettext’ API: ‘import
          ("github.com/snapcore/go-gettext")’

Use or emulate GNU gettext
     This depends on the API:
        • ‘github.com/leonelquinteros/gotext’ API: Emulate
        • ‘github.com/gosexy/gettext’ API: Use
        • ‘github.com/snapcore/go-gettext’ API: Emulate

Extractor
     ‘xgettext’

Formatting with positions
     ‘fmt.Sprintf("%[2]d %[1]d", ...)’

Portability
     fully portable

po-mode marking
     --

   Two examples are available in the ‘examples’ directory: ‘hello-go’
and ‘hello-go-http’.

© manpagez.com 2000-2026
Individual documents may contain additional copyright information.