Translate your Go program into multiple languages.
Go Other
Clone or download

go-i18n Build Status Report card Sourcegraph

go-i18n is a Go package and a command that helps you translate Go programs into multiple languages.


  • v1 is available at 1.x.x tags.
  • v2 is available at 2.x.x tags.

This README always documents the latest version (i.e. v2).

Package i18n GoDoc

The i18n package provides support for looking up messages according to a set of locale preferences.

import ""

Create a Bundle to use for the lifetime of your application.

bundle := &i18n.Bundle{DefaultLanguage: language.English}

Create a Localizer to use for a set of language preferences.

func(w http.ResponseWriter, r *http.Request) {
    lang := r.FormValue("lang")
    accept := r.Header.Get("Accept-Language")
    localizer := i18n.NewLocalizer(bundle, lang, accept)

Use the Localizer to lookup messages.

    DefaultMessage: &i18n.Message{
        ID: "PersonCats",
        One: "{{.Name}} has {{.Count}} cat.",
        Other: "{{.Name}} has {{.Count}} cats.",
    TemplateData: map[string]string{
        "Name": "Nick",
        "Count": 2,
    PluralCount: 2,
}) // Nick has 2 cats.

It requires Go 1.9 or newer.

Command goi18n GoDoc

The goi18n command manages message files used by the i18n package.

go get -u
goi18n -help

Use goi18n extract to create a message file that contains the messages defined in your Go source files.

# en.toml
description = "The number of cats a person has"
one = "{{.Name}} has {{.Count}} cat."
other = "{{.Name}} has {{.Count}} cats."

Use goi18n merge to create message files for translation.

description = "The number of cats a person has"
hash = "sha1-f937a0e05e19bfe6cd70937c980eaf1f9832f091"
one = "{{.Name}} has {{.Count}} cat."
other = "{{.Name}} has {{.Count}} cats."

Use goi18n merge to merge translated message files with your existing message files.

description = "The number of cats a person has"
hash = "sha1-f937a0e05e19bfe6cd70937c980eaf1f9832f091"
one = "{{.Name}} tiene {{.Count}} gato."
other = "{{.Name}} tiene {{.Count}} gatos."

Load the active messages into your bundle.

bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)

For more information and examples:


go-i18n is available under the MIT license. See the LICENSE file for more info.