i18n

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package i18n gives Ken's human web UI runtime-reloadable, drop-in translations.

English (locales/messages.properties) ships embedded as the default AND the fallback; Spanish (locales/messages_es.properties) ships too. To add or override a language, drop a `messages_<lang>.properties` file into the external i18n dir (KEN_I18N_DIR, default <data-dir>/i18n) — it is picked up at runtime, no recompile and no restart (changes are noticed within a couple of seconds).

File format: UTF-8, `key = value`, `#`/`!` comments, blank lines ignored, `{0}` `{1}` … positional placeholders, and the usual `\n \t \\ \uXXXX` escapes. Each file declares its own endonym via the reserved key `lang.self_name` (shown in the language selector). A missing key falls back to English, then to the key itself (so gaps are visible, never blank). Scope: the human web UI only — the AI/MCP surface and the server logs stay English.

Index

Constants

View Source
const (
	// DefaultLang is the built-in default and the fallback for any missing key.
	DefaultLang = "en"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Lang

type Lang struct {
	Code string
	Name string
}

Lang is a selectable language: its code (e.g. "es") and endonym (e.g. "Español").

type Manager

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

Manager holds the merged catalogs (embedded defaults overlaid with the external override dir) and reloads the external dir when its files change.

func New

func New(dir string) *Manager

New builds a Manager, loading the embedded defaults and overlaying dir if it exists. dir need not exist yet — it is watched and picked up when created.

func (*Manager) Has

func (m *Manager) Has(lang string) bool

Has reports whether a language is available.

func (*Manager) Languages

func (m *Manager) Languages() []Lang

Languages returns the available languages (English first, then alphabetical) — the list the UI language selector renders.

func (*Manager) MaybeReload

func (m *Manager) MaybeReload()

MaybeReload re-reads the external dir if its files changed since the last check (throttled). Call once per request, not per T.

func (*Manager) T

func (m *Manager) T(lang, key string, args ...any) string

T translates key in lang, substituting {0}, {1}, … with args. Falls back to English, then to the key itself. Safe for concurrent use.

func (*Manager) TN

func (m *Manager) TN(lang, key string, n int, args ...any) string

TN is T with a simple plural: it resolves key.one when n == 1, else key.other, and makes {0} default to n (extra args fill {1}, {2}, …). en/es/fr share the one/other rule; languages needing richer plural forms use their own paired keys.

Directories

Path Synopsis
Command i18nsync keeps the settings translations honest against the Go registry.
Command i18nsync keeps the settings translations honest against the Go registry.

Jump to

Keyboard shortcuts

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