glibclocale

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT, MIT Imports: 16 Imported by: ? 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 glibclocale reads glibc's compiled locale data in pure Go: the locale-archive and the per-locale directories localedef writes, laid out as glibc's locarchive.h and loadlocale.c read them. It lists the locales a system has, as locale -a does, and reads a locale's LC_NUMERIC, LC_MONETARY and LC_TIME, the last with a strftime over its names and formats.

A locale is found as glibc finds it: with LOCPATH set, only in its directories; otherwise in the archive and then in /usr/lib/locale. A name's codeset is normalized first, so en_US.UTF-8 finds en_US.utf8. Unlike glibc, a name that is not there is an error naming every place searched, never the C locale or a shorter name such as en_US or en. glibc's locale.alias names are not resolved.

musl ships no compiled locale data: there Source.List finds only C and POSIX, and loading any other locale is that error.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoLocale = errors.New("glibclocale: no locale")

ErrNoLocale is the error a source gives for a locale it does not hold.

Functions

func Normalize

func Normalize(name string) string

Normalize is name with its codeset spelled as glibc looks it up and locale -a lists it: lowercase letters and digits only, so en_US.UTF-8 is en_US.utf8 and de_DE.ISO-8859-15 is de_DE.iso885915.

Types

type Monetary

type Monetary struct {
	// contains filtered or unexported fields
}

Monetary is a locale's LC_MONETARY: how it writes an amount of money.

func (Monetary) Format

func (m Monetary) Format(units uint64, scale uint8, numeric Numeric) string

Format writes an amount of money as Numeric.Format writes a number, with the locale's monetary separators and grouping and its currency symbol before, after or in place of the decimal point. An empty monetary decimal point is numeric's, as glibc's strfmon takes it.

type Numeric

type Numeric struct {
	// contains filtered or unexported fields
}

Numeric is a locale's LC_NUMERIC: how it writes a number.

func (Numeric) Format

func (n Numeric) Format(units uint64, scale uint8) string

Format writes units scaled down by scale decimal places, so 123456789 at scale 2 is 1234567.89, with the locale's decimal point, thousands separator and digit grouping.

type Source

type Source struct {
	// contains filtered or unexported fields
}

Source is where locale data is read from: a locale-archive, and directories holding a directory per locale.

func NewSource

func NewSource(archive string, dirs ...string) Source

NewSource reads the locale-archive at archive, "" for none, and then the locale directories under dirs, in order.

func System

func System(env xdg.Env) Source

System is where glibc reads locale data in env: the directories in LOCPATH when it is set; otherwise the archive at $LOCALE_ARCHIVE_2_27 or $LOCALE_ARCHIVE, the variables NixOS's glibc reads, or /usr/lib/locale/locale-archive, and then /usr/lib/locale.

func (Source) Installed

func (s Source) Installed(name string) (bool, error)

Installed reports what glibc's newlocale(LC_CTYPE_MASK, name) would: whether the source holds name's LC_CTYPE. C and POSIX are always installed. A locale that is there but unreadable, or lacks an LC_CTYPE, is an error.

func (Source) List

func (s Source) List() ([]string, error)

List is the locales the source has, sorted, as locale -a names them: C and POSIX, the archive's names and every directory that holds an LC_IDENTIFICATION. A missing archive or directory adds nothing; one that cannot be read is an error.

func (Source) Monetary

func (s Source) Monetary(name string) (Monetary, error)

Monetary reads the LC_MONETARY of the locale name.

func (Source) Numeric

func (s Source) Numeric(name string) (Numeric, error)

Numeric reads the LC_NUMERIC of the locale name.

func (Source) Time

func (s Source) Time(name string) (*Time, error)

Time reads the LC_TIME of the locale name.

type Time

type Time struct {
	// contains filtered or unexported fields
}

Time is a locale's LC_TIME: its names of days and months and its date and time formats, which Time.Format writes.

func (*Time) Format

func (t *Time) Format(format string, at time.Time) (string, error)

Format writes at as glibc's strftime writes format in this locale. It implements the conversions glibc's locales use in their own formats: %a %A %b %B %c %C %d %e %F %H %I %k %l %m %M %p %P %r %R %S %T %x %X %y %Y %z %Z and %%, the - flag, %Ey for the era's year and the O modifier for the locale's alternative digits. %P lowercases ASCII letters only, as glibc does in a UTF-8 locale. A conversion glibc does not know is copied as it stands, as glibc copies it; one glibc knows but Format does not implement, another flag or a field width is an error naming it.

Directories

Path Synopsis
Package glibclocaletest holds glibc compiled locale data for tests, as glibc 2.44's localedef wrote it: the LC_IDENTIFICATION, LC_MONETARY, LC_NUMERIC and LC_TIME of de_DE.utf8, en_GB.utf8, en_US.utf8, fa_IR.utf8 and th_TH.utf8, as locale directories and as a locale-archive holding the same five locales.
Package glibclocaletest holds glibc compiled locale data for tests, as glibc 2.44's localedef wrote it: the LC_IDENTIFICATION, LC_MONETARY, LC_NUMERIC and LC_TIME of de_DE.utf8, en_GB.utf8, en_US.utf8, fa_IR.utf8 and th_TH.utf8, as locale directories and as a locale-archive holding the same five locales.

Jump to

Keyboard shortcuts

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