...

Package i18n

import "github.com/ory/fosite/i18n"
Overview
Index

Overview ▾

func GetLangFromRequest

func GetLangFromRequest(c MessageCatalog, r *http.Request) language.Tag

GetLangFromRequest is a helper func to get the language tag based on the HTTP request and the constructed message catalog.

func GetMessage

func GetMessage(c MessageCatalog, ID string, tag language.Tag, v ...interface{}) string

GetMessage is a helper func to get the translated message based on the message ID and lang. If no matching message is found, it uses ID as the message itself.

func GetMessageOrDefault

func GetMessageOrDefault(c MessageCatalog, ID string, tag language.Tag, def string, v ...interface{}) string

GetMessageOrDefault is a helper func to get the translated message based on the message ID and lang. If no matching message is found, it returns the 'def' message.

type DefaultLocaleBundle

DefaultLocaleBundle is a bundle of messages for the specified locale. The language tag can be arbitrary to allow for unsupported/unknown languages used by custom clients.

type DefaultLocaleBundle struct {
    LangTag  string            `json:"lang"`
    Messages []*DefaultMessage `json:"messages"`
}

func (*DefaultLocaleBundle) Init

func (l *DefaultLocaleBundle) Init() error

Init initializes the default catalog with the list of messages. The lang tag must parse, otherwise this func will panic.

type DefaultMessage

DefaultMessage is a single message in the locale bundle identified by 'ID'.

type DefaultMessage struct {
    ID               string `json:"id"`
    FormattedMessage string `json:"msg"`
}

type MessageCatalog

MessageCatalog declares the interface to get globalized messages

type MessageCatalog interface {
    GetMessage(ID string, tag language.Tag, v ...interface{}) string
    GetLangFromRequest(r *http.Request) language.Tag
}

func NewDefaultMessageCatalog

func NewDefaultMessageCatalog(bundles []*DefaultLocaleBundle) MessageCatalog