Documentation
¶
Overview ¶
Package locale supplies language selection and message formatting contracts for web pages, workers and other Go applications. Providers own interpolation, plural rules and language negotiation; this package starts no services.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Formatter ¶
Formatter translates a namespaced key, using readable source text when it is missing. Text is plain text: HTML renderers must escape it. The provider owns interpolation and plural rules.
type Locale ¶
Locale contains one render's supported content language and formatter.
func SelectLocale ¶
SelectLocale negotiates one render's language. Providers return a supported language and a formatter, including when no preference is supported. Missing or incomplete providers panic because they are composition errors.
Example ¶
package main
import (
"fmt"
"github.com/septagon-oss/platformkit/kit/locale"
)
// A worker can supply readable source messages without an SDK or web renderer.
type sourceMessages struct{}
func (sourceMessages) Select(...string) locale.Locale {
return locale.Locale{Language: "en", Formatter: sourceMessages{}}
}
func (sourceMessages) Text(_ string, fallback string, args ...any) string {
return fmt.Sprintf(fallback, args...)
}
func main() {
messages := locale.SelectLocale(sourceMessages{}, "en")
fmt.Println(messages.Language)
fmt.Println(messages.Text("task.digest", "%d tasks need your review", 2))
}
Output: en 2 tasks need your review