Next: Ruby, Previous: Rust, Up: Individual Programming Languages [Contents][Index]
Three packages are available, that can be used for message localization with PO files:
github.com/leonelquinteros/gotext package.
Documentation: https://pkg.go.dev/github.com/leonelquinteros/gotext
Source code: https://github.com/leonelquinteros/gotext
github.com/gosexy/gettext package.
Documentation: https://pkg.go.dev/github.com/gosexy/gettext
Source code: https://github.com/gosexy/gettext
github.com/snapcore/go-gettext package.
Documentation: https://pkg.go.dev/github.com/snapcore/go-gettext
Source code: https://github.com/canonical/go-gettext
Go programs can be classified as one of:
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.
golang
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.
go
"abc", `abc`
—
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))
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
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
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.
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")
This depends on the API:
github.com/leonelquinteros/gotext API:
Emulate
github.com/gosexy/gettext API:
Use
github.com/snapcore/go-gettext API:
Emulate
xgettext
fmt.Sprintf("%[2]d %[1]d", ...)
fully portable
—
Two examples are available in the examples directory:
hello-go and hello-go-http.
Next: Ruby, Previous: Rust, Up: Individual Programming Languages [Contents][Index]