Documentation
¶
Overview ¶
Package applang holds what a member reads ReputeCast in: their app language and region format (Account & security › Language & region), and the instance defaults for the sign-in page, members who haven't chosen and invitations (connect-and-reach brief §3.7, §5.9). The languages and formats themselves are internal/i18n's.
Index ¶
- Constants
- Variables
- func CheckDefault(language, region string) error
- func ForEmail(ctx context.Context, q *store.Queries, email string) i18n.Lang
- func ForInvitation(ctx context.Context, q *store.Queries, language string) i18n.Lang
- func ForUser(ctx context.Context, q *store.Queries, u store.User) i18n.Lang
- func ForUserID(ctx context.Context, q *store.Queries, id uuid.UUID) i18n.Lang
- func InstanceDefault(ctx context.Context, q *store.Queries) i18n.Lang
- func LanguageCodes() []string
- func Register(h huma.API, s *Service)
- type LanguageOption
- type MemberLanguage
- type Service
- type SuggestionAnswer
Constants ¶
const ( FollowDefault = "default" Auto = "auto" )
What the API stores when a member hasn't chosen: the language follows the instance default, the region follows the language, the clock and the week follow the region.
Variables ¶
var ErrUnknownLanguage = errors.New("applang: unknown language")
ErrUnknownLanguage is an instance default or invitation language ReputeCast isn't translated into.
Functions ¶
func CheckDefault ¶
CheckDefault validates an instance default: a real app language (never the pseudo-locale) and a region format.
func ForEmail ¶
ForEmail returns how the person with this email reads, or the instance default when nobody has it (an invitee).
func ForInvitation ¶
ForInvitation is how an invitation reads: its own language, or the instance default. A language that isn't the instance's uses its own region format.
func ForUser ¶
ForUser returns how a member reads their email: their choices, else the instance defaults. Unknown members read the instance default.
func InstanceDefault ¶
InstanceDefault is how people without an account read: the instance's default language and region format.
Types ¶
type LanguageOption ¶
type LanguageOption struct {
Code string `json:"code" example:"vi"`
Name string `json:"name" example:"Tiếng Việt"`
}
LanguageOption is an app language, named in itself.
func Languages ¶
func Languages() []LanguageOption
Languages returns the app languages the server can answer in, in picker order (the pseudo-locale last, when it's on).
type MemberLanguage ¶
type MemberLanguage struct {
Language string `json:"language" enum:"default,en,vi,en-XA" doc:"default follows the instance default"`
RegionFormat string `json:"regionFormat" enum:"auto,standard,en-US,vi-VN,de-DE,en-GB,es-ES,fr-FR,pt-BR" doc:"auto follows the app language"`
HourCycle string `json:"hourCycle" enum:"auto,h23,h12" doc:"auto follows the region format"`
WeekStart string `json:"weekStart" enum:"auto,monday,sunday" doc:"auto follows the region format"`
}
MemberLanguage is what a member chose in Language & region.
type Service ¶
Service saves members' language choices.
func (*Service) AnswerSuggestion ¶
func (s *Service) AnswerSuggestion(ctx context.Context, in SuggestionAnswer) error
AnswerSuggestion records that a member answered the browser's language suggestion, so no browser offers it again (it is offered once per member). Using the language is saved separately, with Save. Audited as account.language_suggestion_answered.
func (*Service) Save ¶
func (s *Service) Save(ctx context.Context, in MemberLanguage) (MemberLanguage, error)
Save stores a member's choices. Saving is audited as account.language_update.
type SuggestionAnswer ¶
type SuggestionAnswer struct {
Answer string `json:"answer" enum:"use,keep,dismiss" doc:"use switched to the language; keep and dismiss didn't"`
Language string `json:"language" enum:"en,vi" doc:"The language the browser suggested"`
}
SuggestionAnswer is how a member answered "Your browser prefers …".