i18n

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package i18n provides GoForge's bilingual (English/Spanish) message catalogs for human-facing CLI output.

Scope rules (see plan_traduccion.go):

  • Only text GoForge prints itself is translated. Cobra's help templates, --json output, engine errors, and migration names are intentionally left in English.
  • The language is resolved once at startup (Rule A): --lang flag > GOFORGE_LANG > language: in goforge.yaml > LC_ALL/LANG > "en".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Normalize

func Normalize(locale string) string

Normalize reduces a locale string ("es_PE.UTF-8", "en-US", "es") to "es" or "en".

func Resolve

func Resolve(explicit, fromConfig string) string

Resolve picks the display language following Rule A of the i18n plan:

explicit (--lang) > GOFORGE_LANG > fromConfig (goforge.yaml) >
LC_ALL > LANG > "en"

fromConfig may be empty when no config was loaded (e.g. goforge init, goforge version, or a broken goforge.yaml).

func SetLanguage

func SetLanguage(lang string)

SetLanguage activates the catalog for lang. Non-English catalogs are merged over English, so a key missing its translation falls back to the English text instead of breaking output. Anything that is not recognized as Spanish resolves to English.

func T

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

T returns the translation of key, formatted with args (fmt.Sprintf semantics). Missing keys render as "‹key›" so an untranslated string is visible in output instead of failing silently.

func Tn

func Tn(key string, n int, args ...any) string

Tn is T with plural selection: it uses key+"_one" when n == 1 and key+"_other" otherwise. n is prepended to args, so the format string can reference the count as its first verb.

Types

type Catalog

type Catalog map[string]string

Catalog maps message keys to translated format strings.

Jump to

Keyboard shortcuts

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