cldr

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 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 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

View Source
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.

View Source
const (
	ArgStart = ""
	ArgEnd   = ""
)

Marks around what an argument wrote in a message Pseudolocalize transforms: private use characters, which messages do not hold.

View Source
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

func LikelyRegion(lang, script string) string

LikelyRegion returns CLDR's likely region for lang and optional script, by likelySubtags: lang's in script, else lang's, else "".

func LikelyScript

func LikelyScript(lang, region string) string

LikelyScript returns CLDR's likely script for lang and optional region, by likelySubtags: lang's in region, else lang's, else Latin.

func MatchCatalog

func MatchCatalog(langs []string, locale string) string

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

func ParentLocale(lang string) string

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

func Pseudolocalize(tag, s string) string

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.

const (
	LiteralField DateField = iota
	EraField
	YearField
	MonthField
	DayField
	WeekdayField
	DayPeriodField
	HourField
	MinuteField
	SecondField
	FractionField
	ZoneField
)

func (DateField) String

func (f DateField) String() string

String returns the field's name in Intl: "literal", "year", ...

type DateOptions

type DateOptions struct {
	Date, Time Style
	Skeleton   string
}

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

type DatePart struct {
	Field DateField
	Value string
}

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

func DayPeriods(locale string, w NameWidth) []DayPeriod

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

func RegionalOf(locale string) Regional

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 Style

type Style uint8

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

const (
	NoStyle Style = iota
	ShortStyle
	MediumStyle
	LongStyle
	FullStyle
)

type Tag

type Tag struct {
	Lang   string
	Script string
	Region string
	Ext    map[string]string
}

Tag is a parsed BCP 47 language tag (language, optional script and region, and optional -u- Unicode extension key-value pairs).

func ParseTag

func ParseTag(s string) (Tag, bool)

ParseTag parses a BCP 47 tag (accepting '_' or '-' separators). It returns ok=false for empty or malformed tags.

func (Tag) CanonicalRegion

func (t Tag) CanonicalRegion() string

CanonicalRegion returns t.Region if present, else CLDR's likely region for t.Lang and script.

func (Tag) CanonicalScript

func (t Tag) CanonicalScript() string

CanonicalScript returns t.Script if present, else CLDR's likely script for t.Lang and t.Region.

func (Tag) TypeForKey

func (t Tag) TypeForKey(k string) string

TypeForKey returns the value of Unicode extension key k (e.g. "hc", "fw").

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.

Jump to

Keyboard shortcuts

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