String localization tools for Go
Main use for these tools is the localization of error messages.
-
To create suitable errors use the type
Err
from packagemistake
. -
To enrich errors with context, e.g. to build kind of trace, wrap them using
fmt.Errorf
and%w
from the standard library. -
To localize, use the translation tools, e.g. function L10nLocalizeError, generated by the
l10n
command. -
To generate and to update the JSON input file for
l10n
use thel10nextract
command.
The older package message
and the older commands stringl10n
and stringl10nextract
are considered deprecated.
Use "github.com/hwheinzen/stringl10n/mistake"
in your project's import statements.
To get the commands l10n
and l10nextract
do:
$ go install github.com/hwheinzen/stringl10n/cmd/l10n@latest
$ go install github.com/hwheinzen/stringl10n/cmd/l10nextract@latest`
(But maybe you like to have all sources at hand: clone the repository then.)
Some example code can be found in cmd/l10n/example.