applang

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

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

View Source
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

View Source
var ErrUnknownLanguage = errors.New("applang: unknown language")

ErrUnknownLanguage is an instance default or invitation language ReputeCast isn't translated into.

Functions

func CheckDefault

func CheckDefault(language, region string) error

CheckDefault validates an instance default: a real app language (never the pseudo-locale) and a region format.

func ForEmail

func ForEmail(ctx context.Context, q *store.Queries, email string) i18n.Lang

ForEmail returns how the person with this email reads, or the instance default when nobody has it (an invitee).

func ForInvitation

func ForInvitation(ctx context.Context, q *store.Queries, language string) i18n.Lang

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

func ForUser(ctx context.Context, q *store.Queries, u store.User) i18n.Lang

ForUser returns how a member reads their email: their choices, else the instance defaults. Unknown members read the instance default.

func ForUserID

func ForUserID(ctx context.Context, q *store.Queries, id uuid.UUID) i18n.Lang

ForUserID is ForUser by ID.

func InstanceDefault

func InstanceDefault(ctx context.Context, q *store.Queries) i18n.Lang

InstanceDefault is how people without an account read: the instance's default language and region format.

func LanguageCodes

func LanguageCodes() []string

LanguageCodes is Languages without the names.

func Register

func Register(h huma.API, s *Service)

Register adds Account & security › Language & region.

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,de,es,fr,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.

func Choices

func Choices(u store.User) MemberLanguage

Choices returns what a member chose.

type Service

type Service struct {
	Pool  *pgxpool.Pool
	Q     *store.Queries
	Audit *audit.Logger
}

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

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,de,es,fr,vi" doc:"The language the browser suggested"`
}

SuggestionAnswer is how a member answered "Your browser prefers …".

Jump to

Keyboard shortcuts

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