locale

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2025 License: MPL-2.0 Imports: 10 Imported by: 4

README

go-lclocale

Test Documentation Go Report Card

This package is to expose Linux LC_MONETRY locale APIs in Golang via Cgo. The main purpose of this is to make it easier to write localization packages that rely on the hosts actual localization data, rather than relying on some other data source that might be inconsistent between applications.

Requirements

This package requires Cgo, you cannot import depend on it without having gcc installed on the system you are building on.

If you do not have gcc installed you will see errors like:

# github.com/elliotcourant/go-lclocale
..\go\pkg\mod\github.com\elliotcourant\go-lclocale@v0.0.3\monetary.go:84:2: undefined: localeMutex
..\go\pkg\mod\github.com\elliotcourant\go-lclocale@v0.0.3\monetary.go:85:8: undefined: localeMutex
..\go\pkg\mod\github.com\elliotcourant\go-lclocale@v0.0.3\monetary.go:86:12: undefined: setLocale
..\go\pkg\mod\github.com\elliotcourant\go-lclocale@v0.0.3\monetary.go:90:12: undefined: localeconv
..\go\pkg\mod\github.com\elliotcourant\go-lclocale@v0.0.3\search.go:20:13: undefined: setLocale

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCurrencyNotSupported = errors.New("currency not supported")
)

Functions

func GetCurrencyInternationalFractionalDigits added in v0.1.0

func GetCurrencyInternationalFractionalDigits(currency string) (int64, error)

func GetInstalledCurrencies added in v0.1.2

func GetInstalledCurrencies() []string

GetInstalledCurrencies returns a list of ISO currency codes that the current system has information on. Currency codes not in this list may still be valid but the current system has no information on them.

func GetInstalledLocales

func GetInstalledLocales() []string

GetInstalledLocales will return an array of locales that are accepted by the other locale functions in this package for the current host system. The locale names returned here are standardized into a format such as `en_US` and will not include the unicode suffix.

Types

type LConv

type LConv struct {
	// Radix character.
	DecimalPoint []byte
	// Separator for digit groupps to left of radix character.
	ThousandsSep []byte
	// Each element is the number of digits in a group; elements with higher
	// indicies are further left. An element with value 255 means that no further
	// grouping is done. An element with value 0 means that the previous element
	// is used for all groups further left.
	Grouping []uint8
	// First three characters are a currency symbol from ISO4217. Fourth character
	// is the separator. Fifth character is '\0'.
	IntCurrSymbol []byte
	// Local currency symbol.
	CurrencySymbol []byte
	// Radix character.
	MonDecimalPoint []byte
	// Like ThousandsSep above.
	MonThousandsSep []byte
	// Like Grouping above.
	MonGrouping []uint8
	// Sign for positive values.
	PositiveSign []byte
	// Sign for negative values.
	NegativeSign []byte
	// International fractional digits.
	IntFracDigits uint8
	// Local fractional digits.
	FracDigits uint8
	// True if CurrencySymbol precedes a positive value, false if succeeds.
	PCSPrecedes bool
	// True if a space separates CurrencySymbol from a positive value.
	PSepBySpace bool
	// True if CurrencySymbol precedes a negative value, false if it succeeds.
	NCSPrecedes bool
	// True if a space separates the CurrencySymbol from a negative value.
	NSepBySpace bool
	PSignPosn   SignPosition
	NSignPosn   SignPosition
}

LConv contains the numeric and monetary information for a given locale. This data can be used to parse or properly format numbers or monetary amounts to that locales specification.

func GetLConv

func GetLConv(locale string) (*LConv, error)

GetLConv will query the current installed locales on the host system and return the lconv data for the specified locale if it is installed. If the locale is not installed then an error is returned. The locale name may be adjusted to make calling easier. For example; `en_US` may be corrected to `en_US.utf8` on Linux or `en_US.UTF-8` on Darwin depending on what base locales are installed on the system.

type SignPosition

type SignPosition uint8

SignPosition dictates where the negative and positive sign symbols should be placed when formatting a number or monetary amount as a string for a given locale.

const (
	// Parentheses should surround the quantity and currency symbol.
	SignPositionParentheses SignPosition = 0
	// The sign string should precede the quantity and currency symbol.
	SignPositionPreceedsQuantityAndCurrency SignPosition = 1
	// The sign string should succeed the quantity and currency symbol.
	SignPositionSucceedsQuantityAndCurrency SignPosition = 2
	// The sign string should immediately precede the currency symbol.
	SignPositionImmediatelyPreceedsCurrency SignPosition = 3
	// The sign string should immediately succeed the currency symbol.
	SignPositionImmediatelysucceedsCurrency SignPosition = 4
)

Jump to

Keyboard shortcuts

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