Debian Codegraph @

localeinfo.go

raw symbols SCIP
1 // Package localeinfo offers platform-agnostic information about the current locale.
2 // The main entrypoints are Default and NewLocale, which return a Locale.
3 // Most calls of interest are the methods of Locale.
4 package localeinfo
5
6 import (
7 "time"
8 )
9
10 // Locale represents a particular locale, instantiated from Default or NewLocale.
11 // Locale is an interface over platform-specific locale implementations.
12 // Most calls are best-effort, as not all platforms support the same locale information.
13 type Locale interface {
14 // Encoding returns the name of the character encoding used in the selected locale, such as "UTF-8", "ISO-8859-1", or "ANSI_X3.4-1968" (better known as US-ASCII).
15 Encoding() string
16
17 // DateTimeFormat returns a format string to represent time and date in a locale-specific way (corresponds to strftime's %c).
18 DateTimeFormat() string
19
20 // DateFormat returns a format string to represent a date in a locale-specific way (corresponds to strftime's %x).
21 DateFormat() string
22
23 // TimeFormat returns a format string to represent a time in a locale-specific way (corresponds to strftime's %X).
24 TimeFormat() string
25
26 // AM returns the affix for ante meridiem time (corresponds to strftime's %p).
27 AM() string
28
29 // PM returns the affix for post meridiem time (corresponds to strftime's %p).
30 PM() string
31
32 // TimeAMPMFormat returns a format string to represent a time in AM/PM notation in a locale-specific way (corresponds to strftime's %r).
33 TimeAMPMFormat() string
34
35 // Day returns the name of the day of the week (corresponds to strftime's %A).
36 Day(day time.Weekday) string
37
38 // ShortDay returns the abbreviated name of the day of the week (corresponds to strftime's %a).
39 ShortDay(day time.Weekday) string
40
41 // Month returns the name of the month (corresponds to strftime's %B).
42 Month(month time.Month) string
43
44 // ShortMonth returns the abbreviated name of the month (corresponds to strftime's %b).
45 ShortMonth(month time.Month) string
46
47 // Radix returns the decimal separator between the integer and fractional parts of a decimal number.
48 Radix() string
49
50 // ThousandSeparator returns the separator character for thousands.
51 ThousandSeparator() string
52
53 // Currency returns the currency symbol and where the character should be placed relative to a monetary value.
54 Currency() (symbol string, position CurrencyFormat)
55 }
56
57 // Default returns the current locale.
58 func Default() Locale {
59 l, err := NewLocale("")
60 if err != nil {
61 panic(err)
62 }
63 return l
64 }
65
66 // CurrencyFormat describes how the currency symbol should be formatted relative to a monetary value.
67 type CurrencyFormat int
68
69 const (
70 // BeforeValue means prefix, no separation, for example, $1.1
71 BeforeValue CurrencyFormat = iota
72 // AfterValue means suffix, no separation, for example, 1.1$
73 AfterValue
74 // BeforeValueSpace means prefix, 1-character separation, for example, $ 1.1
75 BeforeValueSpace
76 // AfterValueSpace means suffix, 1-character separation, for example, 1.1 $
77 AfterValueSpace
78 // ReplaceRadix means the currency symbol replaces the radix, for example, 1$1
79 ReplaceRadix
80 )
81
82 func (c CurrencyFormat) String() string {
83 switch c {
84 case BeforeValue:
85 return "BeforeValue"
86 case AfterValue:
87 return "AfterValue"
88 case BeforeValueSpace:
89 return "BeforeValueSpace"
90 case AfterValueSpace:
91 return "AfterValueSpace"
92 case ReplaceRadix:
93 return "ReplaceRadix"
94 default:
95 return ""
96 }
97 }