Documentation
¶
Overview ¶
Package cldr formats dates and times by the Unicode CLDR's data, as ICU and Intl write them, and transforms messages for the pseudo locales, for package i18n. tables.go holds the data of the locales of CLDR's modern coverage, generated from a pinned release of cldr-json by go generate (internal/gen).
Index ¶
- Constants
- func FormatDate(locale string, t time.Time, o DateOptions) string
- func FormatNumber(locale string, n float64, o NumberOptions) string
- func LikelyRegion(lang, script string) string
- func LikelyScript(lang, region string) string
- func MatchCatalog(langs []string, locale string) string
- func MonthNames(locale string, w NameWidth, c NameContext) []string
- func ParentLocale(lang string) string
- func Pattern(locale string, o DateOptions) string
- func Pseudolocalize(tag, s string) string
- func WeekdayNames(locale string, w NameWidth, c NameContext) []string
- type DateField
- type DateOptions
- type DatePart
- type DayPeriod
- type NameContext
- type NameWidth
- type NumberOptions
- type Regional
- type Style
- type Tag
Constants ¶
const ( PseudoAccents = "en-XA" PseudoBidi = "ar-XB" )
The pseudo locales, after Android's: en-XA accents and lengthens the source language's messages, ar-XB shows them right to left.
const ( ArgStart = "" ArgEnd = "" )
Marks around what an argument wrote in a message Pseudolocalize transforms: private use characters, which messages do not hold.
const Version = "48.2.0"
Version is the release of the Unicode CLDR the tables come from.
Variables ¶
This section is empty.
Functions ¶
func FormatDate ¶
func FormatDate(locale string, t time.Time, o DateOptions) string
FormatDate writes t, in its location, in the Gregorian calendar, in the way of locale: its patterns, names and digits. Time zones are written as offsets from GMT in the locale's format.
func FormatNumber ¶
func FormatNumber(locale string, n float64, o NumberOptions) string
FormatNumber writes n in the way of locale: its digits, symbols and grouping, by CLDR's data of its default numbering system.
func LikelyRegion ¶
LikelyRegion returns CLDR's likely region for lang and optional script, by likelySubtags: lang's in script, else lang's, else "".
func LikelyScript ¶
LikelyScript returns CLDR's likely script for lang and optional region, by likelySubtags: lang's in region, else lang's, else Latin.
func MatchCatalog ¶
MatchCatalog selects the best supported language in langs for locale, or langs[0] when no supported language matches with high confidence.
func MonthNames ¶
func MonthNames(locale string, w NameWidth, c NameContext) []string
MonthNames returns locale's names of the twelve months, January first.
func ParentLocale ¶
ParentLocale returns the CLDR parent locale of lang, or "" after the base language (or a non-default script root such as zh-Hant).
func Pattern ¶
func Pattern(locale string, o DateOptions) string
Pattern returns the CLDR pattern FormatDate writes for locale and o, as "MMM d, y".
func Pseudolocalize ¶
Pseudolocalize transforms s, a message in the source language whose arguments' text is between ArgStart and ArgEnd, as the pseudo locale tag shows it, keeping what the arguments wrote. Any other tag only drops the marks.
func WeekdayNames ¶
func WeekdayNames(locale string, w NameWidth, c NameContext) []string
WeekdayNames returns locale's names of the seven weekdays, Sunday first, in time.Weekday's order.
Types ¶
type DateField ¶
type DateField uint8
DateField is what a part of a written date is, as Intl's formatToParts names it.
type DateOptions ¶
DateOptions are how FormatDate writes a time: its date, its time or both by style, or else the fields of Skeleton, CLDR's letters in any order ("yMMMd", "jm"), in the order and form the locale writes them. Neither is "yMd".
type DatePart ¶
DatePart is a piece of a written date: a field's value, or the text between fields.
func FormatDateToParts ¶
func FormatDateToParts(locale string, t time.Time, o DateOptions) []DatePart
FormatDateToParts writes t as FormatDate does, in pieces: joined, their values are FormatDate's text.
type DayPeriod ¶
type DayPeriod struct {
// Type is CLDR's name of the period: "am", "pm", "midnight", "noon",
// "morning1", "evening2", ...
Type string
Name string
From, Before int
}
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 noon or evening. 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 locale's day periods: AM and PM, then the flexible periods of its language that it names, by when they start, an instant first.
type NameContext ¶
type NameContext uint8
NameContext is where a name stands: in a date, or alone, as a calendar's heading. Russian writes November "ноября" in a date and "ноябрь" alone.
const ( FormatContext NameContext = iota StandAloneContext )
type NameWidth ¶
type NameWidth uint8
NameWidth is how long a name of a month, a weekday or a day period is.
const ( // WideName is a name in full: "January", "Monday". WideName NameWidth = iota // AbbreviatedName is "Jan", "Mon". AbbreviatedName // NarrowName is a letter or so: "J", "M". NarrowName // ShortName is between abbreviated and narrow, for weekdays: "Mo"; // months and day periods take their abbreviated names. ShortName )
type NumberOptions ¶
type NumberOptions struct {
// MinFraction and MaxFraction bound the fraction digits it keeps,
// rounding to MaxFraction and dropping trailing zeros past
// MinFraction.
MinFraction, MaxFraction int
// NoGroup leaves the integer digits ungrouped.
NoGroup bool
// Percent writes the number times 100 by the percent pattern.
Percent bool
}
NumberOptions are how FormatNumber writes a number.
type Regional ¶
type Regional struct {
FirstDayOfWeek int
HourCycle string
MeasurementSystem string
TemperatureUnit string
}
Regional is how a locale's region reads weeks, times and measures, as CLDR 48's supplemental data has it, Intl's names for its values: FirstDayOfWeek 1 for Monday to 7 for Sunday (ISO 8601), HourCycle "h11", "h12", "h23" or "h24", MeasurementSystem "metric", "us" or "uk", TemperatureUnit "celsius" or "fahrenheit".
func RegionalOf ¶
RegionalOf is locale's regional preferences: what its Unicode extension sets (-u-fw-, -u-hc-, -u-ms-, -u-mu-), else its region's, likely or given, else its language's hours.
type Tag ¶
Tag is a parsed BCP 47 language tag (language, optional script and region, and optional -u- Unicode extension key-value pairs).
func ParseTag ¶
ParseTag parses a BCP 47 tag (accepting '_' or '-' separators). It returns ok=false for empty or malformed tags.
func (Tag) CanonicalRegion ¶
CanonicalRegion returns t.Region if present, else CLDR's likely region for t.Lang and script.
func (Tag) CanonicalScript ¶
CanonicalScript returns t.Script if present, else CLDR's likely script for t.Lang and t.Region.
func (Tag) TypeForKey ¶
TypeForKey returns the value of Unicode extension key k (e.g. "hc", "fw").
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
gen
command
Command gen writes tables.go, the data of the Unicode CLDR package cldr formats dates with, from a pinned release of cldr-json: go generate ./internal/cldr runs it.
|
Command gen writes tables.go, the data of the Unicode CLDR package cldr formats dates with, from a pinned release of cldr-json: go generate ./internal/cldr runs it. |