GNU gettext utilities for Go.
gotext is a native Go implementation of the GNU Gettext utilities. It provides a thread-safe, flexible, and powerful way to handle internationalization (i18n) and localization (l10n) in your Go applications.
msgctxt).xgotext) for string extraction.text/template and html/template pipelines.go get github.com/leonelquinteros/gotext
For a quick start, use the package-level API:
package main
import (
"fmt"
"github.com/leonelquinteros/gotext"
)
func main() {
// Configure package: locales path, language, and domain
gotext.Configure("/path/to/locales", "en_US", "default")
// Simple translation
fmt.Println(gotext.Get("Hello, world!"))
// Translation with variables
fmt.Println(gotext.Get("Hello, %s!", "Gopher"))
}
For more details, see the Getting Started Guide.
gotext includes a command-line tool to extract translatable strings from your Go source code.
Install xgotext:
go install github.com/leonelquinteros/gotext/cli/xgotext@latest
Extract strings:
xgotext -in . -out locales/templates
The command generates .pot templates under locales/templates; merge those templates into language-specific .po files.
See the xgotext Documentation for full usage details.
For managing multiple languages or domains independently:
l := gotext.NewLocale("/path/to/locales", "es_UY")
l.AddDomain("default")
fmt.Println(l.Get("Translate this"))
gotext handles complex pluralization rules defined in PO headers:
// GetN(singular, plural, quantity, args...)
fmt.Println(gotext.GetN("I have one apple.", "I have %d apples.", 5, 5))
See the Plural Forms Guide for more examples.
Supports standard fmt package syntax:
name := "John"
fmt.Println(gotext.Get("Hi, my name is %s", name))
embed.FS) and named %(name)s formatting: see the Advanced Usage Guide.Configure as a colon-separated list (gotext.Configure("/path/to/locales", "es_UY:es:en_US", "default")).Locale.MarshalBinary / UnmarshalBinary.The package expects a standard Gettext directory structure:
/path/to/locales
/en_US
/LC_MESSAGES
default.po
/es_ES
/LC_MESSAGES
default.po
Translation files can live either inside an LC_MESSAGES subdirectory or directly under the language code (/es_ES/default.po); both layouts are supported.
It supports automatic language simplification (e.g., falling back from en_UK to en).
We welcome contributions of all kinds!
gotext is released under the MIT License.
Overall
Maintained
Code review
Go module
Latest release
Releases this year
332 followers · starred Jul 2021
159 followers · starred Aug 2025
675 followers · starred Feb 2019
224 followers · starred Aug 2025
GNU gettext utilities for Go.
gotext is a native Go implementation of the GNU Gettext utilities. It provides a thread-safe, flexible, and powerful way to handle internationalization (i18n) and localization (l10n) in your Go applications.
msgctxt).xgotext) for string extraction.text/template and html/template pipelines.go get github.com/leonelquinteros/gotext
For a quick start, use the package-level API:
package main
import (
"fmt"
"github.com/leonelquinteros/gotext"
)
func main() {
// Configure package: locales path, language, and domain
gotext.Configure("/path/to/locales", "en_US", "default")
// Simple translation
fmt.Println(gotext.Get("Hello, world!"))
// Translation with variables
fmt.Println(gotext.Get("Hello, %s!", "Gopher"))
}
For more details, see the Getting Started Guide.
gotext includes a command-line tool to extract translatable strings from your Go source code.
Install xgotext:
go install github.com/leonelquinteros/gotext/cli/xgotext@latest
Extract strings:
xgotext -in . -out locales/templates
The command generates .pot templates under locales/templates; merge those templates into language-specific .po files.
See the xgotext Documentation for full usage details.
For managing multiple languages or domains independently:
l := gotext.NewLocale("/path/to/locales", "es_UY")
l.AddDomain("default")
fmt.Println(l.Get("Translate this"))
gotext handles complex pluralization rules defined in PO headers:
// GetN(singular, plural, quantity, args...)
fmt.Println(gotext.GetN("I have one apple.", "I have %d apples.", 5, 5))
See the Plural Forms Guide for more examples.
Supports standard fmt package syntax:
name := "John"
fmt.Println(gotext.Get("Hi, my name is %s", name))
embed.FS) and named %(name)s formatting: see the Advanced Usage Guide.Configure as a colon-separated list (gotext.Configure("/path/to/locales", "es_UY:es:en_US", "default")).Locale.MarshalBinary / UnmarshalBinary.The package expects a standard Gettext directory structure:
/path/to/locales
/en_US
/LC_MESSAGES
default.po
/es_ES
/LC_MESSAGES
default.po
Translation files can live either inside an LC_MESSAGES subdirectory or directly under the language code (/es_ES/default.po); both layouts are supported.
It supports automatic language simplification (e.g., falling back from en_UK to en).
We welcome contributions of all kinds!
gotext is released under the MIT License.
Overall
Maintained
Code review
Go module
Latest release
Releases this year
332 followers · starred Jul 2021
159 followers · starred Aug 2025
675 followers · starred Feb 2019
224 followers · starred Aug 2025