golocales

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 7 Imported by: 0

README

Tests on Linux, MacOS and Windows Go Report Card GoDoc

A narrow API for locale aware date and number fornmatting using CLDR 48.1:

type Translator interface {
	// WeekdaysWide returns the full names of the week days, starting with Sunday.
	WeekdaysWide() []string
	// WeekdaysAbbreviated returns the abbreviated names of the week days, starting with Sunday.
	WeekdaysAbbreviated() []string

	// MonthsWide returns the full names of the months, starting with January.
	MonthsWide() []string
	// MonthsAbbreviated returns the abbreviated names of the months, starting with January.
	MonthsAbbreviated() []string

	// FormatDateFull formats the given time using the full date pattern for the locale.
	FormatDateFull(t time.Time) string
	// FormatDateLong formats the given time using the long date pattern for the locale.
	FormatDateLong(t time.Time) string
	// FormatDateMedium formats the given time using the medium date pattern for the locale.
	FormatDateMedium(t time.Time) string
	// FormatDateShort formats the given time using the short date pattern for the locale.
	FormatDateShort(t time.Time) string
	// FormatTimeFull formats the given time using the full time pattern for the locale.
	FormatTimeFull(t time.Time) string
	// FormatTimeLong formats the given time using the long time pattern for the locale.
	FormatTimeLong(t time.Time) string
	// FormatTimeMedium formats the given time using the medium time pattern for the locale.
	FormatTimeMedium(t time.Time) string
	// FormatTimeShort formats the given time using the short time pattern for the locale.
	FormatTimeShort(t time.Time) string

	// FormatNumber formats the given number with the specified number of decimal places.
	FormatNumber(num float64, p int) string
	// FormatAccounting formats the given number as an accounting value with the specified number of decimal places and currency.
	FormatAccounting(num float64, p int, currency string) string
	// FormatPercent formats the given number as a percentage with the specified number of decimal places.
	FormatPercent(num float64, p int) string
	// FormatCurrency formats the given number as a currency value with the specified number of decimal places and currency.
	FormatCurrency(num float64, p int, currency string) string
}

Implemented to replace some old and unmaintained libraries used for this in Hugo. Hugo will most likely soonish move over to use the text/** packages, so I'm not sure how long lived this package will be, either.

Documentation

Overview

Code generated by gen/main.go; DO NOT EDIT.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Translator

type Translator interface {
	// WeekdaysWide returns the full names of the week days, starting with Sunday.
	WeekdaysWide() []string
	// WeekdaysAbbreviated returns the abbreviated names of the week days, starting with Sunday.
	WeekdaysAbbreviated() []string

	// MonthsWide returns the full names of the months, starting with January.
	MonthsWide() []string
	// MonthsAbbreviated returns the abbreviated names of the months, starting with January.
	MonthsAbbreviated() []string

	// FormatDateFull formats the given time using the full date pattern for the locale.
	FormatDateFull(t time.Time) string
	// FormatDateLong formats the given time using the long date pattern for the locale.
	FormatDateLong(t time.Time) string
	// FormatDateMedium formats the given time using the medium date pattern for the locale.
	FormatDateMedium(t time.Time) string
	// FormatDateShort formats the given time using the short date pattern for the locale.
	FormatDateShort(t time.Time) string
	// FormatTimeFull formats the given time using the full time pattern for the locale.
	FormatTimeFull(t time.Time) string
	// FormatTimeLong formats the given time using the long time pattern for the locale.
	FormatTimeLong(t time.Time) string
	// FormatTimeMedium formats the given time using the medium time pattern for the locale.
	FormatTimeMedium(t time.Time) string
	// FormatTimeShort formats the given time using the short time pattern for the locale.
	FormatTimeShort(t time.Time) string

	// FormatNumber formats the given number with the specified number of decimal places.
	FormatNumber(num float64, p int) string
	// FormatAccounting formats the given number as an accounting value with the specified number of decimal places and currency.
	FormatAccounting(num float64, p int, currency string) string
	// FormatPercent formats the given number as a percentage with the specified number of decimal places.
	FormatPercent(num float64, p int) string
	// FormatCurrency formats the given number as a currency value with the specified number of decimal places and currency.
	FormatCurrency(num float64, p int, currency string) string
}

func New

func New(locale string) Translator

New returns a new Translator for the given locale, or nil if the locale is not supported.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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