Go (GNU gettext utilities)

Next: , Previous: , Up: Individual Programming Languages [Contents][Index]


16.5.13 Go

Three packages are available, that can be used for message localization with PO files:

Go programs can be classified as one of:

The three different packages support these two classes of programs differently:

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.


Next: Ruby, Previous: Rust, Up: Individual Programming Languages [Contents][Index]

AltStyle によって変換されたページ (->オリジナル) /