i18n

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package i18n holds the control panel's English and Korean message catalogs (1.1.0).

Catalogs are embedded JSON files, one per language and surface (en/<surface>.json, ko/<surface>.json). A value is plain text with named {placeholders}, or {"one": ..., "other": ...} when a count changes the wording. Values never contain markup: templates own the markup and html/template escapes the result. Placeholders are filled in a single pass, so text inside an argument (a display name such as "{n}") is never interpreted.

Index

Constants

View Source
const (
	English = "en"
	Korean  = "ko"
)

Variables

View Source
var Languages = []string{English, Korean}

Languages lists the supported languages; English is the default and the fallback.

Functions

func Has

func Has(key string) bool

Has reports whether the English catalog defines key.

func JS

func JS(language string) map[string]any

JS returns the js.* messages of a language (English for any missing key) for the page's JSON data block. A counted message becomes {"one": ..., "other": ...}.

func Keys

func Keys(language string) []string

Keys returns the sorted keys of a language's catalog.

func Normalize

func Normalize(language string) string

Normalize returns a supported language code or "".

func Placeholders

func Placeholders(text string) []string

Placeholders lists the placeholder names of a text (for the catalog tests).

func T

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

T returns the message for key in language, with name/value argument pairs. A key missing in the language falls back to English and then to the key itself; the catalog tests keep both cases out of releases.

Types

type Entry

type Entry struct {
	One, Other string
}

Entry is one message. Other is always set; One is the singular form used when the count argument "n" is 1.

func Lookup

func Lookup(language, key string) (Entry, bool)

Lookup returns the raw entry of key in language (for tests).

type Message

type Message struct {
	Key  string
	Args []any
}

Message is a key with arguments, translated when the request language is known.

func M

func M(key string, args ...any) Message

M builds a Message.

func (Message) In

func (m Message) In(language string) string

In translates the message.

Jump to

Keyboard shortcuts

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