Documentation
¶
Overview ¶
Package locale provides a pure-Go emulation of POSIX setlocale/localeconv/ nl_langinfo for PHP. The previous implementation shelled out to libc via cgo, which made behavior depend on whichever locales happened to be generated on the host system (and was not thread-safe). This implementation ships its own locale data, so output is deterministic everywhere.
The "C" and "POSIX" locales are always available and fully populated. A handful of common aliases (en_US, C.UTF-8, etc.) are mapped onto the C locale. Unknown locale names cause SetLocale to return false, matching PHP's behavior on a host that doesn't have the requested locale installed.
Index ¶
Constants ¶
const ( LC_CTYPE phpv.ZInt = iota LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES LC_ALL )
Category codes passed to setlocale(). These are the PHP-visible values and are also used internally as array indices — keep them dense and in the listed order.
> const
const ( D_T_FMT phpv.ZInt = 131112 D_FMT phpv.ZInt = 131113 T_FMT phpv.ZInt = 131114 T_FMT_AMPM phpv.ZInt = 131115 AM_STR phpv.ZInt = 131110 PM_STR phpv.ZInt = 131111 DAY_1 phpv.ZInt = 131079 DAY_2 phpv.ZInt = 131080 DAY_3 phpv.ZInt = 131081 DAY_4 phpv.ZInt = 131082 DAY_5 phpv.ZInt = 131083 DAY_6 phpv.ZInt = 131084 DAY_7 phpv.ZInt = 131085 ABDAY_1 phpv.ZInt = 131072 ABDAY_2 phpv.ZInt = 131073 ABDAY_3 phpv.ZInt = 131074 ABDAY_4 phpv.ZInt = 131075 ABDAY_5 phpv.ZInt = 131076 ABDAY_6 phpv.ZInt = 131077 ABDAY_7 phpv.ZInt = 131078 MON_1 phpv.ZInt = 131098 MON_2 phpv.ZInt = 131099 MON_3 phpv.ZInt = 131100 MON_4 phpv.ZInt = 131101 MON_5 phpv.ZInt = 131102 MON_6 phpv.ZInt = 131103 MON_7 phpv.ZInt = 131104 MON_8 phpv.ZInt = 131105 MON_9 phpv.ZInt = 131106 MON_10 phpv.ZInt = 131107 MON_11 phpv.ZInt = 131108 MON_12 phpv.ZInt = 131109 ABMON_1 phpv.ZInt = 131086 ABMON_2 phpv.ZInt = 131087 ABMON_3 phpv.ZInt = 131088 ABMON_4 phpv.ZInt = 131089 ABMON_5 phpv.ZInt = 131090 ABMON_6 phpv.ZInt = 131091 ABMON_7 phpv.ZInt = 131092 ABMON_8 phpv.ZInt = 131093 ABMON_9 phpv.ZInt = 131094 ABMON_10 phpv.ZInt = 131095 ABMON_11 phpv.ZInt = 131096 ABMON_12 phpv.ZInt = 131097 RADIXCHAR phpv.ZInt = 65536 THOUSEP phpv.ZInt = 65537 YESSTR phpv.ZInt = 327682 YESEXPR phpv.ZInt = 327680 NOSTR phpv.ZInt = 327683 NOEXPR phpv.ZInt = 327681 CRNCYSTR phpv.ZInt = 262159 CODESET phpv.ZInt = 14 )
Item codes for nl_langinfo(). The integer values match GNU libc's langinfo.h on x86_64 Linux so C code that happened to see these constants via goro continues to work.
> const
Variables ¶
This section is empty.
Functions ¶
func GetLocale ¶
GetLocale returns the name of the active locale for the given category. For LC_ALL it returns either a single name (when all categories match) or the POSIX composite form "LC_CTYPE=...;LC_NUMERIC=...;..." otherwise.
func LangInfo ¶
LangInfo returns the value for a single nl_langinfo item from the currently active locale. Unknown item codes return the empty string, matching the behavior of nl_langinfo() on libc with an out-of-range item.
func SetLocale ¶
SetLocale activates the given locale for the specified category. If name is the empty string, the locale is taken from the environment. On success it returns the canonical name of the now-active locale and ok=true. If the requested locale is unknown, it returns ok=false and leaves state alone.
Types ¶
type Lconv ¶
type Lconv struct {
DecimalPoint string
ThousandsSep string
Grouping string
MonDecimalPoint string
MonThousandsSep string
MonGrouping string
PositiveSign string
NegativeSign string
LocalFormat LconvNumericFormat
IntlFormat LconvNumericFormat
}
Lconv mirrors the fields localeconv() returns to PHP.
func Localeconv ¶
func Localeconv() *Lconv
Localeconv returns the localeconv(3) view of the currently-active numeric and monetary locales. LC_NUMERIC feeds the non-monetary fields and LC_MONETARY feeds the rest — matching what C's localeconv() does.
type LconvNumericFormat ¶
type LconvNumericFormat struct {
CurrencySymbol string
FragDigits int8
PCsPrecedes int8
NCsPrecedes int8
PSepBySpace int8
NSepBySpace int8
PSignPosN int8
NSignPosN int8
}
LconvNumericFormat mirrors the subset of struct lconv used for either the local or international monetary format.