/go-intl:go-intl-best-practicefrom go-intl
Implements, migrates, or reviews internationalization in Go applications using go-intl. Covers catalog setup, locale negotiation, namespaces, ICU-style messages, formatting, translation files, and the go-intl CLI.
Ships in go-intl. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Use go-intl to localize Go applications. The import path is github.com/waterkyuu/go-intl, and the package name is intl. The core module requires Go 1.25 or later.
Read the reference relevant to the task:
Call intl.New at application startup to compile messages once, then reuse the read-only *intl.Catalog.
Terminal and desktop applications can keep an intl.Translator in a model or window. HTTP applications bind an intl.Locale or translator for each request.
This program runs independently:
package main
import (
"fmt"
"log"
"github.com/waterkyuu/go-intl"
)
// main compiles the catalog once and binds a translator for one view.
func main() {
catalog, err := intl.New("en",
intl.Define("en", map[string]string{
"Inbox.title": "Inbox",
"Inbox.hello": "Hello, {name}!",
"Inbox.count": "{n, plural, =0 {No messages} one {# message} other {# messages}}",
}),
intl.Define("fr", map[string]string{
"Inbox.title": "Boîte de réception",
}),
)
if err != nil {
log.Fatal(err)
}
t := catalog.Translations("fr", "Inbox")
fmt.Println(t("title")) // Boîte de réception
fmt.Println(t("hello", intl.Values{"name": "Ada"})) // Hello, Ada!
fmt.Println(t("count", intl.Values{"n": 2})) // 2 messages
}
Install with go get github.com/waterkyuu/go-intl.
When the user changes language, bind a new translator from the existing catalog. When translation resources change, build a new catalog and rebind locales and translators; existing bindings still reference the original catalog.
Catalogs can be shared concurrently. During rendering, intl.Values remains owned by the caller; the library only reads its values.
| Use case | API | Behavior |
|---|---|---|
| A configured language tag | catalog.Locale("fr-CA") | Match the closest supported language |
| HTTP language preferences | catalog.Match(header) | Negotiate Accept-Language, including quality weights |
| A translator for a view | catalog.Translations("fr", "Inbox") | Bind a language and optional namespace |
| A translator from an existing locale | locale.Translations("Inbox") | Keep the existing language selection |
intl.New is the application default language. Provide a source for that language.locale.Number use the selected locale.Has returns true, and fallback stops for that key. Omit the key when a translation is missing.locale.Tag() returns the matched supported tag. It can differ from the original preference and from the language supplying an individual message.In an HTTP handler, set the language and cache headers before writing the response:
// Inbox renders a title using this request's language preferences.
func Inbox(catalog *intl.Catalog) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
locale := catalog.Match(r.Header.Get("Accept-Language"))
w.Header().Set("Content-Language", locale.Tag().String())
w.Header().Add("Vary", "Accept-Language")
t := locale.Translations("Inbox")
_, _ = io.WriteString(w, t("title"))
}
}
This snippet requires imports for io, net/http, and go-intl.
Keys use dotted paths such as Inbox.title. Keep complete sentences in messages, pass dynamic data through intl.Values, and express word order and plurals in the message pattern.
| Need | Call | Behavior |
|---|---|---|
| Render text | t("hello", intl.Values{"name": "Ada"}) | Accepts at most one Values map per call |
| Bind a namespace | locale.Scope("Inbox") | Returns a new Locale without modifying the original |
| Nest namespaces | locale.Scope("Inbox").Scope("toolbar") | Equivalent to locale.Scope("Inbox.toolbar") |
| Inspect errors | locale.Scope("Inbox").Format("hello", values) | Returns (string, error) |
| Check key presence | locale.Scope("Inbox").Has("title") | Includes fallback and empty translations |
| Read the original pattern | locale.Scope("Inbox").Raw("count") | Returns (string, bool), including fallback |
After binding Inbox, "title" resolves to Inbox.title, and "toolbar.save" resolves to Inbox.toolbar.save.
Translator and Locale.Text return the fully qualified key for missing messages, missing arguments, or invalid argument types. Use Format when the caller needs an error for logging, diagnostics, or strict validation. Detect missing keys with errors.Is(err, intl.ErrMissingMessage). A formatting failure neither tries another language nor returns partial output.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub waterkyuu/go-intl --plugin go-intlOther plugins' skills for the same job