Documentation
¶
Overview ¶
Package locale implements the ECMA-402 Intl.Locale constructor.
loc, _ := locale.New("en-US", locale.Options{Calendar: "gregory"})
tag := loc.String()
_ = tag
See README.md for usage examples and SPECS/10-locale.md for the contract.
Index ¶
- type List
- type Locale
- func (l Locale) BaseName() string
- func (l Locale) Calendar() string
- func (l Locale) CaseFirst() string
- func (l Locale) Collation() string
- func (l Locale) Equal(other Locale) bool
- func (l Locale) FirstDayOfWeek() string
- func (l Locale) GetCalendars() []string
- func (l Locale) GetCollations() []string
- func (l Locale) GetHourCycles() []string
- func (l Locale) GetNumberingSystems() []string
- func (l Locale) GetTextInfo() TextInfo
- func (l Locale) GetTimeZones() []string
- func (l Locale) GetWeekInfo() WeekInfo
- func (l Locale) HourCycle() string
- func (l Locale) Language() string
- func (l Locale) MarshalText() ([]byte, error)
- func (l Locale) Maximize() Locale
- func (l Locale) Minimize() Locale
- func (l Locale) NumberingSystem() string
- func (l Locale) Numeric() bool
- func (l Locale) Region() string
- func (l Locale) Script() string
- func (l Locale) String() string
- func (l Locale) Tag() language.Tag
- func (l *Locale) UnmarshalText(text []byte) error
- func (l Locale) Variants() []string
- type Options
- type TextInfo
- type WeekInfo
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type List ¶
type List []Locale
List is an ordered Intl locale request list.
A nil or empty List represents omitted locales at constructor boundaries.
type Locale ¶
type Locale struct {
// contains filtered or unexported fields
}
func New ¶
Example (Options) ¶
ExampleNew_options demonstrates Intl.Locale constructor options from ECMA-402.
package main
import (
"fmt"
"github.com/agentable/go-intl/locale"
)
func main() {
loc, err := locale.New("en", locale.Options{
Region: "GB",
Calendar: "gregory",
})
if err != nil {
panic(err)
}
fmt.Println(loc.String())
}
Output: en-GB-u-ca-gregory
func Parse ¶
Example ¶
ExampleParse demonstrates Intl.Locale canonicalization from ECMA-402.
package main
import (
"fmt"
"github.com/agentable/go-intl/locale"
)
func main() {
loc := mustLocale("en-us-u-ca-gregorian-hc-h23")
fmt.Println(loc.String())
}
func mustLocale(tag string) locale.Locale {
loc, err := locale.Parse(tag)
if err != nil {
panic(err)
}
return loc
}
Output: en-US-u-ca-gregory-hc-h23
func (Locale) FirstDayOfWeek ¶
func (Locale) GetCalendars ¶
func (Locale) GetCollations ¶
func (Locale) GetHourCycles ¶
func (Locale) GetNumberingSystems ¶
func (Locale) GetTextInfo ¶
func (Locale) GetTimeZones ¶
func (Locale) GetWeekInfo ¶
Example ¶
ExampleLocale_GetWeekInfo demonstrates Intl.Locale.prototype.getWeekInfo from ECMA-402.
package main
import (
"fmt"
"github.com/agentable/go-intl/locale"
)
func main() {
loc := mustLocale("en-GB")
info := loc.GetWeekInfo()
fmt.Println(info.FirstDay)
fmt.Println(info.Weekend)
}
func mustLocale(tag string) locale.Locale {
loc, err := locale.Parse(tag)
if err != nil {
panic(err)
}
return loc
}
Output: Monday [Saturday Sunday]
func (Locale) MarshalText ¶
func (Locale) NumberingSystem ¶
func (*Locale) UnmarshalText ¶
type TextInfo ¶
type TextInfo struct {
// Direction is the locale text direction. Mirrors getTextInfo() field "direction".
Direction string `json:"direction"`
}
TextInfo describes locale text direction. Mirrors Intl.Locale.prototype.getTextInfo().
type WeekInfo ¶
type WeekInfo struct {
// FirstDay is the locale's first day of week. Mirrors getWeekInfo() field "firstDay".
FirstDay time.Weekday `json:"firstDay"`
// Weekend is the locale's weekend day range. Mirrors getWeekInfo() field "weekend".
Weekend []time.Weekday `json:"weekend"`
}
WeekInfo describes locale week data. Mirrors Intl.Locale.prototype.getWeekInfo().
func (WeekInfo) MarshalJSON ¶
MarshalJSON emits ECMA-402 weekday numbers, Monday=1 through Sunday=7.