i18n

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 11 Imported by: ? 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 says an app's messages in the language it shows: what the code nsgo writes from a package's catalogs (locales/*.yaml) runs on. Apps call that generated code, and Language for the language itself.

A catalog's languages are its own and those other packages supply, as an app supplies German to NSGo's base. The app's catalog decides which language the app shows; every other package's messages follow it.

Index

Constants

View Source
const (
	// NoStyle leaves the date, or the time, out.
	NoStyle = cldr.NoStyle
	// ShortStyle is numeric: "1/5/26", "1:07 PM".
	ShortStyle = cldr.ShortStyle
	// MediumStyle abbreviates: "Jan 5, 2026", "1:07:09 PM".
	MediumStyle = cldr.MediumStyle
	// LongStyle writes the month out: "January 5, 2026".
	LongStyle = cldr.LongStyle
	// FullStyle writes everything: "Monday, January 5, 2026".
	FullStyle = cldr.FullStyle
)
View Source
const (
	// PseudoAccents is en-XA: letters accented, messages a third longer
	// and bracketed, "[Šöŕţ ƀý name one]", so text that is not in a
	// catalog, is cut, or is pieced together shows.
	PseudoAccents = cldr.PseudoAccents
	// PseudoBidi is ar-XB: each word shown right to left, and the app
	// laid out right to left, so what does not mirror shows.
	PseudoBidi = cldr.PseudoBidi
)

The pseudo locales, which test an app's layouts before any translation exists, as Android's do: every catalog says its source language's messages transformed in them.

Variables

This section is empty.

Functions

func Arg

func Arg(s string) string

Arg marks what an argument wrote in a message Pseudo transforms, which keeps it as written. The code nsgo writes calls it.

func FormatDate

func FormatDate(lang string, t time.Time, o DateOptions) string

FormatDate writes t, in its location, in lang's way, in the Gregorian calendar, by CLDR's patterns and names: "Jan 5, 2026", "2026年1月5日". Time zones are written as offsets from GMT.

func FormatInteger

func FormatInteger(lang string, n float64) string

FormatInteger writes n rounded to an integer in lang's way.

func FormatNumber

func FormatNumber(lang string, n float64) string

FormatNumber writes n in lang's way, with up to three fraction digits and grouped: 1,234.5 in English, 1.234,5 in German.

func FormatNumberSkeleton

func FormatNumberSkeleton(lang string, n float64, skeleton string) string

FormatNumberSkeleton writes n in lang's way by an ICU number skeleton, as a message's {n, number, ::.00} does: of its stems percent, integer, the fraction digits (.00 two, .0# one or two) and group-off.

func FormatPercent

func FormatPercent(lang string, n float64) string

FormatPercent writes n, a fraction, as a percentage in lang's way: 25% in English for 0.25, 25 % in German.

func IsPseudo

func IsPseudo(lang string) bool

IsPseudo reports whether lang is a pseudo locale, en-XA or ar-XB.

func Language

func Language(cx *core.Scope) string

Language returns the language the app shows under cx (core.Env.Language): of its catalog's languages, the one that suits the locale it runs in best, else its source language; English for an app without a catalog. Read in a binding, it follows the language as it changes, as Scope.SetLocale or the user changes it.

func Parent

func Parent(lang string) string

Parent returns the language a message missing in lang is looked up in next, by CLDR's parent locales: en-001 for en-AU, en for en-001, zh-Hant for zh-TW; "" after the language alone.

func Pseudo

func Pseudo(lang, s string) string

Pseudo transforms s, a message in the source language whose arguments are marked (Arg), as the pseudo locale lang shows it. The code nsgo writes calls it.

func SetApp

func SetApp(c *Catalog)

SetApp makes c the app's catalog: the languages it shows (core.SetLanguageMatch), nil none. The code nsgo writes for the catalogs of nsgo.yaml's i18n calls it.

func WithHourCycle

func WithHourCycle(cx *core.Scope, lang string) string

WithHourCycle is lang with the hour cycle the user set under cx as its Unicode extension (-u-hc-), which FormatDate writes times in; lang as it is where they set none.

Types

type Catalog

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

Catalog is the languages a package's messages are written in: its source language, first, its translations, and the languages other packages supply. The code nsgo writes makes one per package.

func NewCatalog

func NewCatalog(source string, translations ...string) *Catalog

NewCatalog returns the languages of a catalog written in source.

func (*Catalog) Add

func (c *Catalog) Add(lang string)

Add adds a language another package supplies the messages of.

func (*Catalog) Languages

func (c *Catalog) Languages() []string

Languages returns the catalog's languages, the source's first.

func (*Catalog) Match

func (c *Catalog) Match(locale string) string

Match returns the catalog's language that suits locale best, as zh-Hant suits zh-TW and de suits de-CH, or the source language when none does. A pseudo locale (IsPseudo) suits every catalog.

func (*Catalog) Source

func (c *Catalog) Source() string

Source returns the language the catalog is written in.

type Category

type Category uint8

Category is a number's plural category in a language, by CLDR's rules: one and other in English, other alone in Chinese, six in Arabic.

const (
	Other Category = iota
	Zero
	One
	Two
	Few
	Many
)

func Cardinal

func Cardinal(lang string, n float64) Category

Cardinal returns the plural category of n in lang, as FormatNumber writes it: 1.0004 is written 1, whose category in English is one.

func Ordinal

func Ordinal(lang string, n float64) Category

Ordinal returns the ordinal category of n in lang: one, two, few and other in English (1st, 2nd, 3rd, 4th).

func (Category) String

func (c Category) String() string

String returns the category's name in a message: "one", "other", ...

type DateOptions

type DateOptions = cldr.DateOptions

DateOptions are how FormatDate writes a time: its date, its time or both by style, or else the fields of a skeleton of CLDR's letters ("yMMMd", "jm") in the order and form the language writes them.

type RegionalSettings

type RegionalSettings = cldr.Regional

RegionalSettings are how weeks, times and measures read, in Intl's names: FirstDayOfWeek 1 for Monday to 7 for Sunday, HourCycle "h11", "h12", "h23" or "h24", MeasurementSystem "metric", "us" or "uk", TemperatureUnit "celsius" or "fahrenheit".

func Regional

func Regional(cx *core.Scope) RegionalSettings

Regional returns how the user reads weeks, times and measures under cx: what they set on the platform (core.Env.LocaleSettings), else what the region of the locale the app runs in does, by CLDR's data. Read in a binding, it follows them as they change.

type Style

type Style = cldr.Style

Style is the length of a date or a time as CLDR's patterns write it.

type Texts

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

Texts are a catalog's messages without arguments in one language, by index: their text one after another, each as long in bytes as lens says, 0 where the language lacks one. The code nsgo writes holds a language's as one string, which the linker writes as it is, rather than a string for each, whose header the program must fix up.

func NewTexts

func NewTexts(text string, lens []uint16) *Texts

NewTexts returns the texts in text, as long as lens says.

func (*Texts) At

func (t *Texts) At(i int) string

At returns the message at i, "" where the language lacks it.

Jump to

Keyboard shortcuts

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