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 DatePattern(lang string, o DateOptions) 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 MonthNames(lang string, w NameWidth, c NameContext) []string
- func Parent(lang string) string
- func Pseudo(lang, s string) string
- func SetApp(c *Catalog)
- func WeekdayNames(lang string, w NameWidth, c NameContext) []string
- func WithHourCycle(cx *core.Scope, lang string) string
- type Catalog
- type Category
- type DateField
- type DateOptions
- type DatePart
- type DayPeriod
- type NameContext
- type NameWidth
- 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 ( LiteralField = cldr.LiteralField EraField = cldr.EraField YearField = cldr.YearField MonthField = cldr.MonthField DayField = cldr.DayField WeekdayField = cldr.WeekdayField DayPeriodField = cldr.DayPeriodField HourField = cldr.HourField MinuteField = cldr.MinuteField SecondField = cldr.SecondField FractionField = cldr.FractionField ZoneField = cldr.ZoneField )
const ( // WideName is a name in full: "January", "Monday". WideName = cldr.WideName // AbbreviatedName is "Jan", "Mon". AbbreviatedName = cldr.AbbreviatedName // NarrowName is a letter or so: "J", "M". NarrowName = cldr.NarrowName // ShortName is between abbreviated and narrow, for weekdays: "Mo"; // months and day periods take their abbreviated names. ShortName = cldr.ShortName )
const ( // FormatContext is a name in a date: Russian "5 ноября". FormatContext = cldr.FormatContext // StandAloneContext is a name alone: Russian "ноябрь". StandAloneContext = cldr.StandAloneContext )
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 DatePattern ¶
func DatePattern(lang string, o DateOptions) string
DatePattern returns the CLDR pattern FormatDate writes for lang and o, as "M/d/y" or "MMM d, y, h:mm a", for a date input's fields and their order. Text in apostrophes is literal: "d 'de' MMMM 'de' y".
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, in the digits, symbols and grouping of its default numbering system by CLDR: 1,234.5 in English, 1.234,5 in German, ١٬٢٣٤٫٥ in Egyptian Arabic, −2 in Swedish.
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 MonthNames ¶
func MonthNames(lang string, w NameWidth, c NameContext) []string
MonthNames returns lang's names of the twelve months, January first, in the Gregorian calendar.
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.
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 WeekdayNames ¶
func WeekdayNames(lang string, w NameWidth, c NameContext) []string
WeekdayNames returns lang's names of the seven weekdays, Sunday first, indexed by time.Weekday. RegionalOf(lang).FirstDayOfWeek says which starts a week.
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 DateField ¶
DateField is what a part of a written date is: a field, or the text between fields. String returns Intl's name for it, as "dayPeriod".
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 DatePart ¶
DatePart is a piece of a written date: a field's value, or the text between fields.
func FormatDateToParts ¶
func FormatDateToParts(lang string, t time.Time, o DateOptions) []DatePart
FormatDateToParts writes t as FormatDate does, in pieces, as Intl's formatToParts: {MonthField "Jan"} {LiteralField " "} {DayField "5"} ... Joined, their values are FormatDate's text.
type DayPeriod ¶
DayPeriod is a part of the day as a language names it: AM and PM, and the flexible periods its times may write, such as 中午 and 晚上 in Chinese. From and Before are minutes after midnight; a period of an instant, midnight or noon, has them equal, and one past midnight has Before less than From.
func DayPeriods ¶
DayPeriods returns lang's day periods, for reading typed times: AM and PM, then the flexible periods of its language that it names, by when they start.
type NameContext ¶
type NameContext = cldr.NameContext
NameContext is where a name stands: in a date, or alone, as a calendar's heading.
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.
func RegionalOf ¶
func RegionalOf(lang string) RegionalSettings
RegionalOf returns how lang's region reads weeks, times and measures, by CLDR's data: what its Unicode extension sets (-u-fw-, -u-hc-, -u-ms-, -u-mu-), else its region's, given or likely ("zh" is China's), else its language's hours. Regional reads the user's settings too.
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.