i18n

package
v1.0.21 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package i18n provides lightweight internationalization for the DWS CLI.

At startup call Init() (or let the package auto-init via the init function). Use T("key") to get a translated string, or Tf("key", args...) for formatted translations with fmt.Sprintf-style placeholders.

The active language is resolved from the DWS_LANG environment variable first, then falls back to the LANG environment variable. If neither is set or does not match a supported locale, "en" (English) is used as the default.

Message catalogs are stored as JSON files under locales/ and embedded at compile time via go:embed.

Supported locales:

  • "en" — English (default)
  • "zh" — Simplified Chinese

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init()

Init resolves the active locale from environment variables and loads the message catalogs from embedded JSON files. Safe to call multiple times; only the first call takes effect.

func Lang

func Lang() string

Lang returns the current language tag string ("en" or "zh").

func LangTag

func LangTag() language.Tag

LangTag returns the resolved language.Tag.

func SetLang

func SetLang(tag string)

SetLang overrides the active locale. Intended for testing.

func T

func T(key string) string

T returns the translated string for the given message key. If the key is not found in the active catalog, the key itself is returned.

func Tf

func Tf(key string, args ...any) string

Tf returns a formatted translated string. The key is looked up in the active message catalog and the result is passed through fmt.Sprintf with the provided arguments.

Types

This section is empty.

Jump to

Keyboard shortcuts

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