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
- func Arg(s string) string
- func FormatDate(lang string, t time.Time, o DateOptions) string
- func FormatInteger(lang string, n float64) string
- func FormatNumber(lang string, n float64) string
- func FormatNumberSkeleton(lang string, n float64, skeleton string) string
- func FormatPercent(lang string, n float64) string
- func IsPseudo(lang string) bool
- func Language(cx *core.Scope) string
- func Parent(lang string) string
- func Pseudo(lang, s string) string
- func SetApp(c *Catalog)
- func WithHourCycle(cx *core.Scope, lang string) string
- type Catalog
- type Category
- type DateOptions
- type RegionalSettings
- type Style
- type Texts
Constants ¶
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 )
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 ¶
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 ¶
FormatInteger writes n rounded to an integer in lang's way.
func FormatNumber ¶
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 ¶
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 ¶
FormatPercent writes n, a fraction, as a percentage in lang's way: 25% in English for 0.25, 25 % in German.
func Language ¶
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 ¶
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 ¶
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.
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 ¶
NewCatalog returns the languages of a catalog written in source.
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.
func Cardinal ¶
Cardinal returns the plural category of n in lang, as FormatNumber writes it: 1.0004 is written 1, whose category in English is one.
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 ¶
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 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.