i18n

package module
v0.0.0-...-93bbc99 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 11, 2025 License: MIT Imports: 16 Imported by: 0

README

I18N

Go Reference Go Report Card codecov License

A Go internationalization library that provides template integration and message extraction capabilities. This library offers a simple way to add i18n support to Go applications using Go templates, with automatic message extraction and integration with Go's standard golang.org/x/text package.

Installation

go get github.com/gowool/i18n

# install tool
go get -tool github.com/gowool/i18n/cmd/i18n
go get -tool golang.org/x/text/cmd/gotext

Extractor

package locales

//go:generate go tool i18n extract --dir ./themes --pkg locales --out locales/messages.json --gofile locales/gotext_stub.go --ext .html --ext .gohtml
//go:generate go tool gotext -srclang=en-US update -out=catalog.go -lang=en-US,it-IT,fr-FR,de-DE github.com/dummy/example/locales
go generate ./...

License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FuncMap = template.FuncMap{
	"L":    language.MustParse,
	"T":    trans,
	"t":    trans,
	"i18n": trans,
}

Functions

func Fallback

func Fallback() language.Tag

func Printer

func Printer(tag language.Tag) *message.Printer

func SetFallback

func SetFallback(tag language.Tag)

func SetPrinter

func SetPrinter(tag language.Tag, printer *message.Printer)

func T

func T(tag language.Tag, key message.Reference, a ...any) string

Types

type Extractor

type Extractor struct {
	// contains filtered or unexported fields
}

func NewExtractor

func NewExtractor(dir, out, pkg, goFile string, exts ...string) *Extractor

func (*Extractor) Extract

func (e *Extractor) Extract() error

type Message

type Message struct {
	ID        string   `json:"id"`                  // original message (singular or formatted)
	Positions []string `json:"positions,omitempty"` // file:line:col where found
}

Message holds extracted message metadata.

type OutputJSON

type OutputJSON struct {
	Messages []*Message `json:"messages"`
}

OutputJSON is the top-level JSON structure we write (simple map by ID).

Directories

Path Synopsis
cmd
i18n command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL