Skip to content

v0.6.0

Latest

Choose a tag to compare

@DABH DABH released this 03 Oct 06:38
· 5 commits to main since this release
381bd9f

Two more Go frameworks. English output is unchanged; existing catalogs need no migration.

kong

github.com/DABH/localizer/kongx: one extra option localizes a kong application.

ctx := kong.Parse(&cli, kong.Name("yourcli"), kong.Description("..."), kongx.Localize(locales.FS))

It translates the help of every command, flag and argument (help:"..." tags, kong.Description, group titles), kong's own headings and hints (Usage:, Flags:, Commands:, Arguments:, Run "yourcli --help" for more information.) and the parse errors it prints, with the error label of the yourcli: error: … line. Built-in translations ship for the seven languages. Guide: https://locale.dev/guides/kong/

urfave/cli v3

github.com/DABH/localizer/urfave: one line before Run localizes a urfave/cli v3 application.

urfave.Localize(cmd, locales.FS)
err := cmd.Run(context.Background(), os.Args)

It translates every command's Usage, UsageText, Description, ArgsUsage, Category and deprecation text, every flag's usage, category, default text and deprecation text, the help templates (headings and usage-line tokens), the help, --help, --version and completion texts, the (default: X) suffix, the version line, and the usage errors and cli.Exit messages written to the error writers. The package changes urfave/cli's package-level templates and hooks for the process; the guide lists them. Guide: https://locale.dev/guides/urfave/

Runtime

  • localizer.WriterMode(w, mode): Writer with an explicit mode, for adapters that wrap a framework's help or error writer.
  • Built-in catalogs are organized per framework (internal/builtin/<framework>/); an application sees the union.

Service

The onboarding pull request now recognizes kong and urfave/cli repositories: the extractor reads kong help tags and kong.Description, urfave Command and flag fields and cli.Exit messages; the patcher adds the kong option or the urfave statement, or tells the maintainer the one line when the call site is ambiguous.

Examples

examples/kong-demo and examples/urfave-demo next to the Cobra examples/demo.