locale

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package locale provides cross-platform language detection and translation.

Detection priority:

  1. CCL_LANG environment variable
  2. ~/.ccl/config.yaml lang field
  3. OS-level language setting (via environment on Unix, Win32 API on Windows)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Current

func Current() string

Current returns the current full locale code (e.g. "zh-CN", "en-US").

func IsChinese

func IsChinese() bool

IsChinese returns true when the current language is a Chinese variant.

func SetLanguage

func SetLanguage(code string) string

SetLanguage overrides the language at runtime and returns the canonical form.

func T

func T(zh, en string) string

T returns the Chinese or English string based on the current language. Call: T("中文文本", "English text")

func Tf

func Tf(zhPattern, enPattern string, args ...any) string

Tf is like T but supports fmt.Sprintf formatting. Call: Tf("中文 %s 模板", "English %s template", arg)

Types

type LanguageManager

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

LanguageManager manages the current language and provides translations.

Jump to

Keyboard shortcuts

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