Documentation
¶
Overview ¶
Package lang says icebath's texts in a user's language: messages named by their English and said where they reach the user, the catalogs that hold a language's words for them, the plural rules, number, date and list forms of each language, and which way it is written. It keeps no language of its own: each request, window and chat app carries the one it speaks in its context
Index ¶
- Constants
- Variables
- func Agree(english, translation string, form plural.Form, isPlural bool) bool
- func Errorf(english string, args ...any) error
- func Fallbacks(id string) []string
- func FormName(form plural.Form) string
- func FormOf(name string) (plural.Form, bool)
- func Key(english, one, context string, plural, plain bool) string
- func Marked(text string) bool
- func Mirror(r rune) rune
- func Needed(id string) []plural.Form
- func Normalize(value string) string
- func Parts(key string) (english, one, context string, plural bool)
- func Resolve(value string, have func(id string) bool) (string, bool)
- func Takes(format string) int
- func Valid(value string) bool
- func Visual(line []rune) (order []int, backward []bool)
- func With(ctx context.Context, l *Language) context.Context
- type Arg
- func Ago(d time.Duration) Arg
- func Clock(t time.Time) Arg
- func Copy(name, english string) Arg
- func Date(t time.Time) Arg
- func Day(t time.Time) Arg
- func Either(items ...string) Arg
- func List(items ...string) Arg
- func ListMore(parts int, items ...string) Arg
- func Number(x any) Arg
- func OnOff(on bool) Arg
- func Ordinal(n int) Arg
- func Size(bytes float64) Arg
- func Span(d time.Duration) Arg
- func When(t time.Time) Arg
- type Catalog
- type Entry
- type Error
- type Known
- type Language
- func (l *Language) Ago(d time.Duration) string
- func (l *Language) As(context, english string, args ...any) string
- func (l *Language) Capital(text string) string
- func (l *Language) Clock(t time.Time) string
- func (l *Language) Copy(name, english string) string
- func (l *Language) Date(t time.Time) string
- func (l *Language) Day(t time.Time) string
- func (l *Language) DayMonth(t time.Time) string
- func (l *Language) Either(items ...string) string
- func (l *Language) Endonym() string
- func (l *Language) EnglishName() string
- func (l *Language) Error(err error) string
- func (l *Language) Has(key string) bool
- func (l *Language) ID() string
- func (l *Language) Known() Known
- func (l *Language) List(items ...string) string
- func (l *Language) ListMore(parts int, items ...string) string
- func (l *Language) MonthYear(t time.Time) string
- func (l *Language) N(count any, one, other string, args ...any) string
- func (l *Language) Number(x any) string
- func (l *Language) OnOff(on bool) string
- func (l *Language) Ordinal(n int) string
- func (l *Language) RightToLeft() bool
- func (l *Language) Say(t Text) string
- func (l *Language) Size(n float64) string
- func (l *Language) Span(d time.Duration) string
- func (l *Language) T(english string, args ...any) string
- func (l *Language) Tag() language.Tag
- func (l *Language) Upper(text string) string
- func (l *Language) When(t time.Time) string
- func (l *Language) Year(t time.Time) string
- type Text
- type Verb
Constants ¶
const ( ContextOpen = " ⟨" ContextClose = "⟩" PluralMark = " ⟨plural⟩ " )
Marks a key is read back by, which no English, form or context of a site holds: the opening and closing marks of a context at the end of a key, and the mark between the one and the other form of a text whose words follow a count. A text of any number of lines is never taken for a plural, as only the mark makes one
Variables ¶
var English = New(Known{ID: "en", Endonym: "English", English: "English"})
English as the sites write it, with no catalog
Functions ¶
func Agree ¶
Whether a translation takes the arguments of its English with the same verbs: every one of them for a text and for the other form of a plural, a part of them for another form of a plural, which may leave the count out. A percent sign that starts no placeholder is free in both: a language writes a percentage its own way, such as German's "70 %"
func Errorf ¶
Errorf returns an error for the user: a full sentence that says what happened and what to do, formatted like fmt.Errorf. Each %w wraps its argument, which errors.Is and errors.As then find
func Fallbacks ¶
Ids the words of the language are looked for under, the language first and then each shorter tag it falls back to; Traditional Chinese never falls to Simplified
func Key ¶
Key of a text with the English, the one form of a plural, the context, whether it is a plural and whether it is data
func Marked ¶
Whether a text holds a character the marks of a key are made of, which no English, form or context of a site may hold, as a key made of it would read back as another
func Mirror ¶
The character a line shown right to left takes in place of the one given: its counterpart for one that points a way or opens a side, the same character for any other
func Needed ¶
Forms the words of the language take by its CLDR cardinal rules, in the order of CLDR: those of the whole counts, and other always, the form every plural falls back to and, in a language whose whole counts all take another (Russian, Ukrainian), the form of a count with a fraction, such as the 1.5 seconds of a length of time. What a plural entry of its catalog must hold
func Normalize ¶
Id as it is compared: lower case, trimmed, underscores as dashes, without the encoding or the modifier a locale names
func Parts ¶
What a key stands for, as Key made it: its English, the other form of a plural. The one form and whether it is a plural. The context of a text said with one. A key with no mark is its English whatever it holds, line breaks among them
func Resolve ¶
The language a value stands for among those have holds: an id, a name of a language, a regional tag or a locale such as pt_BR.UTF-8, a regional tag standing for its base and a tag of Traditional Chinese for zh-hant. False when it stands for none of them
func Takes ¶
Count of the arguments a format takes: the highest that any of its placeholders names, for its verb, its width or its precision; none for a format without a placeholder
func Valid ¶
Whether the value can be the id of a language: a tag the language data of the program reads
func Visual ¶
Order a line of a right to left interface is shown in on a terminal that reorders nothing: for each place on the screen from the left, the index of the character of the line that goes there. The line is read as a paragraph of a right to left language by the Unicode bidirectional algorithm, so runs of right to left letters read from the right, words and numbers of left to right scripts keep their order, and what stood first stands rightmost. Each character is one rune standing for one cell, wide or not. Beside the order, whether the character at each place is read right to left, which takes the mirrored form of a character that points a way
Types ¶
type Arg ¶
type Arg struct {
// contains filtered or unexported fields
}
A value a language says its own way, given to a message as one of its arguments and written there with %s: a number, a length of time, a size, a date, a list, a switch's state, a place in an order, or registry copy inside a sentence
func Copy ¶
Registry copy inside a sentence, such as the title of a setting or of a chat app: said as Language.Copy says it
func ListMore ¶
Items in at most the parts given: all of them when they fit, otherwise the first ones and how many more, such as a, b and 6 more
func Number ¶
A number with the grouping, decimal mark and digits of the language, up to three decimals
func Span ¶
A length of time in the largest unit that divides it, in words: 1 hour, 90 minutes, 1.5 seconds
func (Arg) MarshalJSON ¶
func (*Arg) UnmarshalJSON ¶
type Entry ¶
One entry of a catalog: the language's words for a text, or the forms of words that follow a count
func (Entry) Form ¶
Words of the form, those of other when the entry has no such form. The words of an entry that is no plural
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
An error a user reads: a message said in their language where it reaches them, and the errors its %w verbs wrap behind it. Its Error is the English
type Known ¶
A language: its id, what it calls itself, what English calls it (which the model is told) and whether it is written right to left
type Language ¶
type Language struct {
// contains filtered or unexported fields
}
A language as a request, a window or a chat app speaks it: what it is, and its catalogs in the order their words win
func New ¶
The language with its catalogs, the first layer's words winning. What no layer holds is said in the English of its site
func Spoken ¶
Language the context carries, false when it carries none, such as the work of a scheduled job no person asked for
func (*Language) Ago ¶
How long ago something was, rounded down to its largest whole unit: 45 seconds ago, 3 minutes ago, 2 days ago
func (*Language) Clock ¶
A time of day as the language tells it, on a clock of 24 hours or of 12: the language's words for 12 on its clock say which
func (*Language) Copy ¶
Registry copy in the language, such as the title of a setting: the words of its structural name where a layer has them, then those of its English, then, for copy made from data, the words of the template its English was made from with the data in its holes (a structural name with * for the data's part saying it differently there), otherwise the English
func (*Language) Date ¶
A date: the day, its month by name and the year, in the order of the language
func (*Language) DayMonth ¶
A day of a month with the month's short name and no year, as an axis of days marks it: 2 Nov
func (*Language) EnglishName ¶
What English calls the language
func (*Language) Error ¶
The error as a user reads it in the language: every message of its chain said in it, what is no message as it is written
func (*Language) ListMore ¶
Items in at most the parts given: all of them when they fit, otherwise the first ones and how many more
func (*Language) MonthYear ¶
A month by its short name with its year, as an axis of months marks it: Nov 2026
func (*Language) Number ¶
A number with the grouping, decimal mark and digits of the language, up to three decimals
func (*Language) Ordinal ¶
A place in an order as a number with the ending the language's ordinal rules give it
func (*Language) RightToLeft ¶
Whether the language is written right to left
func (*Language) Size ¶
A count of bytes in the largest unit that fits, the units of 1024 for a count they divide and of 1000 for any other
func (*Language) Span ¶
A length of time in the largest unit that divides it, in words: 1 hour, 90 minutes, 1.5 seconds
type Text ¶
type Text struct {
// contains filtered or unexported fields
}
A text icebath says to a person: the English it is written in at its site and its arguments, said in a user's language where it reaches them. Its English is its name: a catalog of a language holds the language's words under it. The zero Text says nothing
func As ¶
A message whose English is said two ways, such as Off as a state and as a command: a lower case word chosen at the site tells this way apart from the others, so a language says each its own way
func N ¶
A message whose words follow a count, such as one session and three sessions: the count picks the form by the plural rules of the language it is said in, one and other being the English forms. The count is not an argument unless it is given among the args too
func Plain ¶
Data that reads the same in every language, such as a path or a name a user gave, where a text is asked for
func T ¶
A message: its English as a format of fmt verbs (%s, %d, %[2]s) and its arguments. An argument that is a Text, an Arg or an error is said in the language the message is said in, written with %s or %v. Any other is data and is written as fmt writes it
func (Text) Key ¶
Key a catalog keeps the text's words under: its English. The English one form, the plural mark and the other form of a text whose words follow a count. The English and its context in the marks of a context for a text said with one. Empty for data. Parts reads it back
func (Text) MarshalJSON ¶
func (*Text) UnmarshalJSON ¶
type Verb ¶
A placeholder of a format: the argument it takes, counted from 1, and its verb with its flags, width and precision as fmt reads them, written one way whatever way the format writes them: the flags in the order # 0 + -, the width, a point and the precision, the verb; a width or precision read from an argument as * with that argument in brackets